Navigating a Structure Using Cell Arrays in a For Loop
Show older comments
I'm using a full Academic Suite MATLAB version 2018a.
Why does the following work:
scan1 = 'scan398';
plot1 = 'Item1';
ext = 'units'
figure 1
surface(a.(scan1).rel_X, a.(scan1).rel_Y, a.(scan1).(plot1).(ext), 'LineStyle', 'none')
%graph settings here%
but below produces the error: Argument to dynamic structure reference must evaluate to a valid field name.
scans = {'scan398', 'scan405', 'scan439'}
plot = {'Item1' , 'Item2' , 'Item3'}
ext = 'units'
for j = 1:length(scans)
frma(j) = scans(j)
for i = 1:length(plot)
figure
surface(a.(frma(j)).rel_X, a.(frma(j)).rel_Y, a.(frma(j)).(plot(i)).(ext), 'LineStyle', 'none')
%graph settings here%
end
end
I entered a breakpoint to see what the 'frma' cell array looks like:
frma =
1×1 cell array
{'scan398'}
What's inside the surface function?
a.'scan398'.'Item1'
%or
a.scan398.Item1
It should be working if it's the second case. If it's the first, how do I fix it?
Accepted Answer
More Answers (0)
Categories
Find more on Creating, Deleting, and Querying Graphics Objects 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!