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.

조회 수: 3 (최근 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에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by