How do I make multiple figures from one matrix of data in a loop?

2 views (last 30 days)
I have a matrix of 4373x30 called X and need figure a plot for each three columns, so separate figures for columns 1-3, 4-6, 7-10 etc. I can of course write each plot out separately but this is very time consuming so there must be a way of putting it all in a for loop So far i have:
for i=1:3:28
for j=3:3:30
figure;
plot(X(:,i,j)
end
end
but this just plots hundreds of figures and I'm not sure why?
  1 Comment
Stephen23
Stephen23 on 23 Feb 2015
Note that it is best to avoid using i and j for loop variable names, as these are both names of the inbuilt imaginary unit .

Sign in to comment.

Answers (1)

dpb
dpb on 23 Feb 2015
Edited: dpb on 23 Feb 2015
You're looping over two indices for some reason and creating a figure every pass...to just do groups of columns
nCols=3 % for generality if change number
for iCol=1:nCols:size(X,2)
figure
plot(X(:,iCol:iCol+nCols-1)
end

Categories

Find more on Graphics Performance in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!