Why the loop return only the last element ?
Afficher commentaires plus anciens
I'm trying to change the size of subplots using a for loop.So what I really want to do is this:
clear
n=9;
pos=cell(1,n);
for i=1:n
a(i)=subplot(n,1,i);
pos{i}= get(a(i),'position');
if i<9
set(gca,'xtick',[])
end
pos{i}(1,4)=(pos{i}(1,4))/2;
set(a(i),'position',pos{i});
end
pos{8}(1,2)=(pos{8}(1,2)) - 0.045;
pos{7}(1,2)=(pos{7}(1,2)) - 0.09;
pos{6}(1,2)=(pos{6}(1,2)) - 0.1350;
pos{5}(1,2)=(pos{5}(1,2)) - 0.18;
pos{4}(1,2)=(pos{4}(1,2)) - 0.2250;
pos{3}(1,2)=(pos{3}(1,2)) - 0.2700;
pos{2}(1,2)=(pos{2}(1,2)) - 0.3150;
pos{1}(1,2)=(pos{1}(1,2)) - 0.3600;
set(a(8),'position',pos{8});
set(a(7),'position',pos{7});
set(a(6),'position',pos{6});
set(a(5),'position',pos{5});
set(a(4),'position',pos{4});
set(a(3),'position',pos{3});
set(a(2),'position',pos{2});
set(a(1),'position',pos{1});
But,I want to do this in a easier way .So I tried make all this using just a for loop :
clear
n=9;
pos=cell(1,n);
for i=1:n
a(i)=subplot(n,1,i);
pos{i}= get(a(i),'position');
if i<9
set(gca,'xtick',[])
end
pos{i}(1,4)=(pos{i}(1,4))/2;
for d=8:-1:0
y(d+1)=0.045*d;
t=fliplr(y);
end
pos{i}(1,2)=(pos{i}(1,2))-t(i);
set(a(i),'position',pos{i});
end
The point is that this code return only the last element.I mean,just the subplot(9,1,9).
How can I solve this ?
Thanks, Luiz
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!