MATLAB: I need to plot many plots in a loop function.

forloopsplotssubplots

function data=coa08xxx_lines(n)
load xydata
for u=X(:,n)
for i=Y(:,n)
data= plot(u,i);
end
end
end
This code only plots the graph of n, but i want it to plot all the graps. for example if n=3, then i want the plot of 3, 2 and 1 to appear as subplots.

Best Answer

function data=coa08xxx_lines(n)
load xydata
ii=ceil(n/3);
jj=ceil(n/ii);
for k=1:n
subplot(ii,jj,k)
plot(u(:,k),y(:,k));
end