How to use y1 y2 y3... variables in for loop?

조회 수: 9 (최근 30일)
Timur
Timur 2013년 2월 6일
Hi,
I need to autoplot several graphs at once. Variables I have are y1, y2, y3,..., y8.
How should I change the following code, so y1 will be changing to y2, y3 and etc.?
for j=1:8,
subplot(1,8,j);bar3(y1);view(-90,0);
end
Thank you

채택된 답변

TAB
TAB 2013년 2월 6일
편집: TAB 2013년 2월 6일
Y = {y1;y2;y3;y4;y5;y6;y7;y8};
for j=1:8,
subplot(1,8,j);bar3(Y{j});view(-90,0);
end
  댓글 수: 3
Jan
Jan 2013년 2월 6일
A general method is to avoid to include an index in the name of a variable. Better use y{1}, y{2}..., than cat(1, y{:}) creates the matrix directly.
José-Luis
José-Luis 2013년 2월 6일
Please accept an answer if it helped you.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by