Why do I get an unhelpful error message when assigning a “struct” only to the end of the last structure array entry initialized by empty brackets?
I am initializing an empty structure array using empty brackets:
>> myStruct(3).myField = [];
Then, all the initialized structure arrays are of type "double":
>> {class(myStruct(1).myField), class(myStruct(2).myField), class(myStruct(3).myField)}
ans =
1×3 cell array
{‘double’} {‘double’} {‘double’}
Why do I get an unhelpful error of "Conversion to double from struct is not possible" only when appending a "struct" to the end of the last array entry?
For example, the following code snippet executes without an error, which changes the class of the first and second entries of "myStruct" to "struct":
>> myStruct(1).myField(2) = struct(‘myVar’, 3);
>> myStruct(2).myField(2) = struct(‘myVar’, 3);
>> {class(myStruct(1).myField), class(myStruct(2).myField), class(myStruct(3).myField)}
ans =
1×3 cell array
{‘struct’} {‘struct’} {‘double’}
However, executing a similar line of code for the last entry of "myStruct" does throw an error:
>> myStruct(3).myField(2) = struct(‘myVar’, 3);
Conversion to double from struct is not possible.I am initializing an empty structure array using empty brackets:
>> myStruct(3).myField = [];
Then, all the initialized structure arrays are of type "double":
>> {class(myStruct(1).myField), class(myStruct(2).myField), class(myStruct(3).myField)}
ans =
1×3 cell array
{‘double’} {‘double’} {‘double’}
Why do I get an unhelpful error of "Conversion to double from struct is not possible" only when appending a "struct" to the end of the last array entry?
For example, the following code snippet executes without an error, which changes the class of the first and second entries of "myStruct" to "struct":
>> myStruct(1).myField(2) = struct(‘myVar’, 3);
>> myStruct(2).myField(2) = struct(‘myVar’, 3);
>> {class(myStruct(1).myField), class(myStruct(2).myField), class(myStruct(3).myField)}
ans =
1×3 cell array
{‘struct’} {‘struct’} {‘double’}
However, executing a similar line of code for the last entry of "myStruct" does throw an error:
>> myStruct(3).myField(2) = struct(‘myVar’, 3);
Conversion to double from struct is not possible. I am initializing an empty structure array using empty brackets:
>> myStruct(3).myField = [];
Then, all the initialized structure arrays are of type "double":
>> {class(myStruct(1).myField), class(myStruct(2).myField), class(myStruct(3).myField)}
ans =
1×3 cell array
{‘double’} {‘double’} {‘double’}
Why do I get an unhelpful error of "Conversion to double from struct is not possible" only when appending a "struct" to the end of the last array entry?
For example, the following code snippet executes without an error, which changes the class of the first and second entries of "myStruct" to "struct":
>> myStruct(1).myField(2) = struct(‘myVar’, 3);
>> myStruct(2).myField(2) = struct(‘myVar’, 3);
>> {class(myStruct(1).myField), class(myStruct(2).myField), class(myStruct(3).myField)}
ans =
1×3 cell array
{‘struct’} {‘struct’} {‘double’}
However, executing a similar line of code for the last entry of "myStruct" does throw an error:
>> myStruct(3).myField(2) = struct(‘myVar’, 3);
Conversion to double from struct is not possible. structinitialization MATLAB Answers — New Questions