Creating figures according to slice number

Hi I have data that contains slice number and coordinates. first column is slice number (changing), the last two columns are x y coordinates. I want to create figures of the coordinates with the same slice number, and once the slice number change, a new figure is generated. Could you help me? Here is what I have so far.
slice=realdata(:,3);
row=realdata(:,4);
col=realdata(:,5);
correctlength=length(slice)-1;
for i=1:correctlength
if slice(i)==slice(i+1)
plot(row(i),col(i))
end
end

 Accepted Answer

the cyclist
the cyclist on 9 Jul 2013
Edited: the cyclist on 9 Jul 2013
Here is a self-contained example with some made-up data.
% Made up data with three "slices", each with a different number of points
realdata = [rand(9,2),[1;1;1;1;2;2;2;3;3],rand(9,5)];
slice=realdata(:,3);
row=realdata(:,4);
col=realdata(:,5);
correctlength=length(slice);
for i=1:correctlength
if (i==1) || (slice(i)~=slice(i-1))
figure
hold on
end
plot(row(i),col(i),'.')
end

2 Comments

yes the edited one worked perfectly. the first version was missing the last slice. thanks!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!