MATLAB: Assign a ‘double’ variable to struct

fieldsnon-structure arraystruct

I have a variable as such:
A.b = 'example';
And I want to change it to:
A.b.c = 2;
How can I do it without it prompting:
'Field assignment to a non-structure array object'
It worked on matlab's version before 2014.
Thank you,
Ziv

Best Answer

A.b = 'example';
A.b = struct('c', 2); % Overwrite field "b"
Or:
A.b = 'example';
A.b = [];
A.b.c = 2
It is strange, that this works with the empty matrix, if it fails with an error for a char vector. But the first method is better, because it overwrites the field clearly.