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 次查看(过去 30 天)
% 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');

采纳的回答

Nick
Nick 2018-11-7
编辑:Nick 2018-11-7
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by