필터 지우기
필터 지우기

Running two counter in one for statement

조회 수: 6 (최근 30일)
Rich Cavanaugh
Rich Cavanaugh 2018년 4월 12일
댓글: Rich Cavanaugh 2018년 4월 12일
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
  댓글 수: 1
Rich Cavanaugh
Rich Cavanaugh 2018년 4월 12일
that works perfectly. Thanks a million

댓글을 달려면 로그인하십시오.

추가 답변 (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