Running two counter in one for statement

6 次查看(过去 30 天)
Hello, I am trying to wright a for loop that has two counters that run counter to each other.
here is one of my attempts limiting the size of .rows and .cols to 3 in reality those values will be much larger
for (i = 1:3)
for(j = 3:-1:1)
handles.checkerDR{i}=...
handles.([handles.rows{i} handles.cols{j}]).String;
end
end
what I would like is checkerDR to be a cell array of
checkerDR{1}=handles.([handles.rows{1} handles.cols{3}).String;
checkerDR{2}=handles.([handles.rows{2} handles.cols{2}).String;
checkerDR{3}=handles.([handles.rows{3} handles.cols{1}).String;
so on and so forth does anyone have any ideas? i have been trying different iterations for a while and im not sure how to get this to work Thanks in advance

采纳的回答

Geoff Hayes
Geoff Hayes 2018-4-12
Rich - try using just one for loop
maxIter = 3;
for k=1:maxIter
handles.checkerDR{k}=...
handles.([handles.rows{k} handles.cols{maxIter - k + 1}]).String;
end

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by