for loop within for loop
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
Hey,
I want to make two for loops. the first for loop is when the values are j = [1:4,5:8,9:2,13:6,7:20,21:24]
because I am using this for a subplot, so when j = 1 or j=5 or j=9 or j=13 or j=17 or j=21 then i=1.
When j=2, j=6 ,j=10 , j=14 , j=18 or j=22 then i=2.
When j=3, j=7, j=11, j=15, j=19 or j=23 then i=3.
When j=4, j=8, j=12, j=16, j=20, j=24 then i=4.
채택된 답변
ME
2019년 11월 4일
2 개 추천
I don't know what you want to do inside those for loops so I can't give you full code but the loops you'll want are:
for i=1:4;
for j=i:4:24;
end
end
댓글 수: 12
Hinna Ahmed
2019년 11월 4일

Hinna Ahmed
2019년 11월 4일
thank you for your answer but it still doesn't work. subplot should go upto subplot(1,4,4).
ME
2019년 11월 4일
for i=1:4;
for j=i:4:24;
end
subplot(1,4,i);
plot(...)
end
Depending on how you store your results, you may need to do your plotting commands with some (i:4:end) commands in there to miss out a bunch of zeros.
Hinna Ahmed
2019년 11월 4일
shouldn't there be anything inside the second loop? :)
ME
2019년 11월 4일
My assumption was that you needed to get the correct combinations of i and j for some further calculations. I was imagining that you'd fill those calculations in within the j for loop. Otherwise I can't understand what you are actually plotting.
Hinna Ahmed
2019년 11월 4일
편집: Hinna Ahmed
2019년 11월 4일
I am plotting a matrix from a table.
imagesc(t/60,F,DataTable3.Coh_time{j,1})
j is actualle the row of its location. The length of the table is 24. the first 4 rows should be plotted in a subplot together and then the next 4 rows in another subplot and so on (upto 6 plots). There should be 6 plots each containing 4 subplots. The imagesc function is actually plotting the matrix.
ME
2019년 11월 4일
Well then if that's what you want then that should have been stated in your initial question!
If you could attach the data table to your question that would be extremely helpful!
Hinna Ahmed
2019년 11월 4일

Hinna Ahmed
2019년 11월 4일
편집: Hinna Ahmed
2019년 11월 4일
I am sorry, that I didn't state it in the initial question
No problem, it's just that people are giving up their time to answer these questions and that is all for nothing if the questions aren't clear.
Anyway, if you want the first four rows of your cell array to be figure one, rows 5-8 in figure two and so on, then you can use:
for p=1:6
figure
for i=1:4
subplot(2,2,i)
imagesc(C{((p-1)*4)+i,1})
end
end
where p is for the six figures and i is for the four rows. I have assumed a 2x2 layout for the subplots in each figure window but if you'd prefer then all in a line then swap subplot(2,2,i) for either subplot(1,4,i) or subplot(4,1,i).
I hope this helops now!
Hinna Ahmed
2019년 11월 4일
THANK YOU SO MUCH!! :D
ME
2019년 11월 4일
No problem, happy to help!
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Annotations에 대해 자세히 알아보기
태그
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
