MATLAB: How to use y1 y2 y3… variables in for loop

3d plotsfor loopgraphloopplot

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

Best Answer

Y = {y1;y2;y3;y4;y5;y6;y7;y8};
for j=1:8,
subplot(1,8,j);bar3(Y{j});view(-90,0);
end