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

 Réponse acceptée

the cyclist
the cyclist le 9 Juil 2013
Modifié(e) : the cyclist le 9 Juil 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 commentaires

Tina
Tina le 9 Juil 2013
Thank you!
Tina
Tina le 9 Juil 2013
yes the edited one worked perfectly. the first version was missing the last slice. thanks!

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by