|
How do I initialize this so that all the fields of the structure are null, except for the index (idx) which should equal 1?
I've tried:
s.xtrma=[];
...
s.idx=1;
freq(nFreqs)=s
But that only set the last frequency's index to 1. The rest were null.
I tried:
freq(nFreqs).xtrma=[];
freq(nFreqs).idx=1;
Generates an "assignment between unlike types" error.
freq(nFreqs).xtrma=[];
freq(nFreqs).idx=1;
Generates an "assignment between unlike types" error.
freq(nFreqs).xtrma=[];
freq(nFreqs).idx=[1 1 1 1 1 1 1 1 1];
Somehow this does not cause an error, but it puts an array of nine ones in the last frequency (which is nine, in this case), when I wanted a one in all nine frequencies.
freq(nFreqs).xtrma=[];
freq(nFreqs).idx={1 1 1 1 1 1 1 1 1};
Almost the same as above, except freq(1,9).idx is a cell array of nine ones.
freq(nFreqs).xtrma=[];
freq(nFreqs).idx={1,1,1,1,1,1,1,1,1};
Puts the whole cell in the last (ninth) frequency.
This works, but I have more than just these two variables (also, I don't know yet how to dynamically set the size of the cell array of ones):
freq=struct('xtrma', [], 'idx', {1,1,1,1,1,1,1,1,1})
I've read the help file on struct and this article: http://blogs.mathworks.com/loren/2008/02/01/structure-initialization/. But I can't figure out how to preallocate all idx to 1.
Can anyone help? Thanks.
Jeff
|