How do I save for loop data from series of images? I am creating two polygons along the borders in a set of images. i want to save the polygon data for every loop. Currently it is overwriting and only saving the last loops data.
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
% code
for k = t0:56
[epi,xi,yi] = roipoly(echo(:,:,k)); %manually click along epicardial border;
[endo,xi2,yi2] = roipoly(echo(:,:,k)); %manually click along endocardial border;
end
figure; plot(xi,yi,'b');
hold on
plot(xi,yi,'b+');
plot(xi2,yi2,'r');
plot(xi2,yi2,'ro');
0 commentaires
Réponse acceptée
Nick
le 7 Nov 2018
Modifié(e) : Nick
le 7 Nov 2018
The easiest way to store something in MATLAB is to use arrays and index them using your loop index or a separate counter if your loop index is not a simple 1:X.
I am assuming you just want to store the data and access them separately after the loop. An easy solution is to use cell arrays.
% make cell arrays
xEpi = cell(1,numel(t0:56));
yEpi = cell(1,numel(t0:56));
xEndo = cell(1,numel(t0:56));
xEndo = cell(1,numel(t0:56));
% loop through data, assuming t0 is not 1;
counter = 1;
for k = t0:56
[~,xEpi{counter},yEpi{counter}] = roipoly(echo(:,:,k)); % u can use the tilda instead of a trash variable if you do not use epi or endo
[~,xEndo{counter},yEndo{counter}] = roipoly(echo(:,:,k)); %manually click along endocardial border;
counter = counter + 1;
end
You could then plot them all like you did in your previous example but then using a for loop:
% plot them all on individual figures:
for ii = 1:numel(xEpi) % assuming the same number of Epi and Endo
figure;
plot(xEpi{ii},yEpi{ii},'b', 'Marker', '+');
hold on
plot(xEndo{ii},yEndo{ii},'r', 'Marker','o');
end
% or plot them all on the same figure:
figure
for ii = 1:numel(xEpi)
plot(xEpi{ii},yEpi{ii},'b', 'Marker', '+');
if ii==1
hold on
end
plot(xEndo{ii},yEndo{ii},'r', 'Marker','o');
end
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!