Navigating a Structure Using Cell Arrays in a For Loop
显示 更早的评论
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?
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Creating, Deleting, and Querying Graphics Objects 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!