structure

How can I move variables into and out of a structure akin to LOAD and SAVE in MATLAB?

╄→гoц情女王★ 提交于 2019-11-29 09:56:25
Is there a quick way (i.e. one line) to dump a collection of variables "in" a structure, using the variable names as the structure fields? The "load" function basically does this but saving and loading to a temporary file seems ugly. For example: clear a = 'adsf' b = rand(10); x = var2struct(a,b) x.a x.b or better yet: x = var2struct(['a';'b']) Also, what about the reverse (i.e. dumping the field values to the current scope as variables named after the fields)?: clear x.a='asdf' x.b=rand(10); dumpstruct(x) a b Also, here's a related newsgroup thread . Aside from using LOAD and SAVE , there is

How would you structure a forum's DB schema? [closed]

£可爱£侵袭症+ 提交于 2019-11-29 08:48:28
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 3 years ago . I'm building a little forum for practice. I see that forums like phpBB store the thread text in a separate table. Why? Why not store it all in the same table? Something like: thread_id, thread_date, thread_text, thread_author Why is it done this way? How would you do it? 回答1:

How to save a structure array to a text file

穿精又带淫゛_ 提交于 2019-11-29 07:42:48
In MATLAB how do I save a structure array to a text file so that it displays everything the structure array shows in the command window? You have to define a format for your file first. Saving to a MATLAB workspace file (.MAT) If you don't care about the format, and simply want to be able to load the data at a later time, use save , for example: save 'myfile.mat' structarr That stores struct array structarr in a binary MAT file named "file.mat". To read it back into your workspace you can use load : load 'myfile.mat' Saving as comma-separated values (.CSV) If you want to save your struct array

When should we not use #pragma pack?

时间秒杀一切 提交于 2019-11-29 06:22:18
问题 In C, when we use structures, when would it be inappropriate to use #pragma pack directive..? an addition to the question..... Can someone please explain more on how might the accessing of unaligned data specially with a pointer fail? 回答1: Firmware developer here. #pragma pack is very familiar territory. I'll explain. In general you should not use #pragma pack . Yes, it will make your structures smaller in memory since it eliminates all padding between struct members. But it can make

Python, ctypes, multi-Dimensional Array

妖精的绣舞 提交于 2019-11-29 02:40:17
I have structure in Python code and in C code. I fill these fields ("bones_pos_vect",((c_float*4)*30)), ("bones_rot_quat",((c_float*4)*30)) in python code with the right values, but when I request them in C code, I get only 0.0 from all array cells. Why do I lose the values? All other fields of my structures work fine. class SceneObject(Structure): _fields_ = [("x_coord", c_float), ("y_coord", c_float), ("z_coord", c_float), ("x_angle", c_float), ("y_angle", c_float), ("z_angle", c_float), ("indexes_count", c_int), ("vertices_buffer", c_uint), ("indexes_buffer", c_uint), ("texture_buffer", c

Java many to many association map

主宰稳场 提交于 2019-11-29 01:57:06
I have two classes, ClassA and ClassB , as well as a "many to many" AssociationClass . I want a structure that holds the associations between A and B so that I can find the counterpart for each instance of A or B. I thought of using a Hashmap, with pair keys: Hasmap<Pair<ClassA, ClassB>, AssociationClass> associations; This way, I can add and remove an association between two instances of ClassA and ClassB , and I can query a relation for two given instances. However, I miss the feature of getting all associations defined for a given instance of ClassA or ClassB . I could do it by brute force

initialization of anonymous structures or unions in C1X

柔情痞子 提交于 2019-11-28 23:14:19
I have the following question: How are anonymous structures (or unions) properly initialized according to the current C1X draft ? Is this legal: struct foo { int a; struct { int i; int j; }; int b; }; struct foo f = { 1, 2, 3, 4 }; struct foo g = { 1, { 2 }, 3 }; In GCC, g.j == 0 and g.b == 3 , while in tcc g.j == 3 and g.b == 0 . The current draft says: "[...] unnamed members of objects of structure and union type do not participate in initialization. Unnamed members of structure objects have indeterminate value even after initialization.". Can this be really true? Isn't struct foo h = { 0 };

Accessing the underlying struct of a PyObject

跟風遠走 提交于 2019-11-28 22:10:32
I am working on creating a python c extension but am having difficulty finding documentation on what I want to do. I basically want to create a pointer to a cstruct and be able to have access that pointer. The sample code is below. Any help would be appreciated. typedef struct{ int x; int y; } Point; typedef struct { PyObject_HEAD Point* my_point; } PointObject; static PyTypeObject PointType = { PyObject_HEAD_INIT(NULL) 0, /*ob_size*/ "point", /*tp_name*/ sizeof(PointObject), /*tp_basicsize*/ 0, /*tp_itemsize*/ 0, /*tp_dealloc*/ 0, /*tp_print*/ 0, /*tp_getattr*/ 0, /*tp_setattr*/ 0, /*tp

Quickest way to initialize an array of structures to all-0's?

▼魔方 西西 提交于 2019-11-28 21:13:04
I'm trying to initialize an array of structures to all-0's, using the below syntax: STRUCTA array[MAX] = {0}; However, I'm getting the following warning from gcc : warning: missing braces around initializer What am i doing wrong - is there another/better way to do this ? It the first member of your struct has a scalar type, use STRUCTA array[MAX] = {{ 0 }}; If the first member of your struct happens to be another struct object, whose first member has scalar type, then you'll have to use STRUCTA array[MAX] = {{{ 0 }}}; and so on. Basically, you have to open a new level of nested {} every time

uml classdiagram constructor with parameters

拟墨画扇 提交于 2019-11-28 21:08:32
I am a complete ROOKIE at this so I need some help on it. How would you create uml class diagram and constructors with parameters. for default (no parameters) you do policyholder() for diagram and pseudo-code for parameters would you do the same thing policyholder (policynumber, service class, and customer age) for class diagrams and pseudo-code. It also asked to initialize each attribute to value where an object of this type can be instantiated, If a policy number is not between 1000 and 999 inclusive, then set the policy number to 0. (policy number is attribute) The common way is to write