Unable to perform assignment because dot indexing is not supported for variables of this type.
3 views (last 30 days)
Show older comments
Roxanne Esguerra
on 23 Jul 2020
Commented: Roxanne Esguerra
on 24 Jul 2020
Hi this is my code,
experiments(1).num = 33;
experiments(1).code = 'x';
experiments(1).weights = [200.34 202.45];
experiments(1).height.feet = 5;
experiments(1).height.inches = 6;
experiments(2).num = 11;
experiments(2).code = 't';
experiments(2).weights = [111.45 111.11];
experiments(1).height.feet = 7;
experiments(1).height.inches = 2;
I get this error whenever I run it,
Unable to perform assignment because dot indexing is not supported
for variables of this type.
Error in experimentsinitialization (line 4)
experiments(1).height.feet = 5;
When I try to call height of experiments(1), I get this,
>> experiments(1).height
ans =
5 6
However, I must get something like this,
>> experiments(1).height
ans =
feet: 5
inches: 6
What should I replace? or add?
Thank you in advance!
0 Comments
Accepted Answer
Walter Roberson
on 23 Jul 2020
The code you posted is self-consistent. However, in some earlier code, you set
experiments(1).height = [5 6]
and you did not remove that.
My guess is that you modified your code along the way, but you did not clear the experiments variable so it still has the old data around.
3 Comments
Walter Roberson
on 24 Jul 2020
clear experiments
would remove that old data.
If you want to keep old data, but you want to convert height from being a vector of two elements, into being a struct with feet and inches, then
fi = experiments(1).height;
experiments(1).height = struct('feet', fi(1), 'inches', fi(2));
This would replace the entire experiments(1).height with a struct, and there is no problem replacing an entire variable.
More Answers (0)
See Also
Categories
Find more on Structures in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!