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

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

 Akzeptierte Antwort

TAB
TAB am 6 Feb. 2013
Bearbeitet: TAB am 6 Feb. 2013

0 Stimmen

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 Kommentare

Timur
Timur am 6 Feb. 2013
Thanks! Worked just fine!
Jan
Jan am 6 Feb. 2013
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 am 6 Feb. 2013
Please accept an answer if it helped you.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 6 Feb. 2013

Community Treasure Hunt

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

Start Hunting!

Translated by