I'm currently writing some code in MatLab v7.4 that runs a function on a structured array, performs a calculation from the data in that structured array and then inserts the results of that calculation into that same array as a new field. I'm having trouble adding this data into the structured array as the field was previously empty. The following is an example of what I wish to do:
A.) Previously empty field within structure is called ".val":
matlabbatch{1,1}.spm.stats.fmri_spec.sess(1,1).regress.val
B.) Input vector of values into ".val" from a variable containing these values ("globals"):
matlabbatch{1,1}.spm.stats.fmri_spec.sess(1,1).regress.val = globals
When I attempt add this field, MatLab displays the following error:
??? A dot name structure assignment is illegal when the structure is empty.
Use a subscript on the structure.
Why is this and how may I correct it? I also receive this error when attempting to input character strings into previously empty fields within structures. Seeing as this was not a problem within v7.1, why can't I do this with v.7.4?
Any assistance anyone could provide would be greatly appreciated.
Thanks!
-Jeff
> A.) Previously empty field within structure is called ".val":
> matlabbatch{1,1}.spm.stats.fmri_spec.sess(1,1).regress.val
>
> B.) Input vector of values into ".val" from a variable containing these values ("globals"):
> matlabbatch{1,1}.spm.stats.fmri_spec.sess(1,1).regress.val = globals
>
> When I attempt add this field, MatLab displays the following error:
>
> ??? A dot name structure assignment is illegal when the structure is empty.
> Use a subscript on the structure.
Your example is a little bit confusing. I try it with less substructs:
X = struct([]);
X.A = 9;
This produces the same error message. Does this equal your description "previously empty field within a structure is called val" ?
X(1).A = 9 % works.
This new behaviour is described in the release logs of the online documentation, e.g. http://www.mathworks.com/access/helpdesk/help/techdoc/index.html. I cannot find the description at the moment, but I've think I've read it there.
Good luck, Jan