0
votes

I am thinking of creating a structure like Q.Q.Q.W(1,12).x1...Q.Q.Q.W(1,12).x40 so I have 12 fields for W and for each of them 40 pairs: field-value inside (cells, strings, integers). I want to preallocate this structure. In this case I already have an existing structure like this but with data, and depending on conditions I either modify these data and save to my new structure, or just go further with empty preallocated structure.

So I have to obtain a structure preallocated of dimensions exactly like my structure with datas, but thi sone has to be empty. How to do it without entering all these 12 times 50 names and so ?

would be just like s = struct(obj) from help, but should not contain the content of obj, but be empty.

help please if you have any idea

1
Rather than answer this directly, may I suggest that you look at the map data structure instead mathworks.co.uk/help/techdoc/matlab_prog/brqqo5e-1.html, rather than implement your own key value system - learnvst
can I ask you for a more direct question? because I cannot cope with that what you suggested - beginh

1 Answers

0
votes

Indeed, it does not seem to be the best of choices on how to store your data -- the resulting structure wouldn't be the easiest thing in the world to manipulate.

Nevertheless, if your customer/client/whomever expects you to return the same data structure as you were given, it is a legitimate use case.

So, you can do something like

for ii = 1:40               
    Q.Q.Q.W(12).(['x' num2str(ii)]) = [];
end

to create the initial structure.

I didn't quite understand what you want to fill the structure with initially -- can you clarify this a bit?