How to store data in each iteration

3 次查看(过去 30 天)
DM
DM 2022-2-17
回答: KSSV 2022-2-17
Hi,
I have the following code in which I calculate the time curve of each non-zero region of my image. In each iteration I would like to store the values of each time-cruve (y) because I wouls also like to plot the average curve of the individual time-curves (sum the individual curves/ number of individual curves).
Below is my code to plot the individual time-curves.
image = My 4D image;
mask = My 3D mask;
p=bwlabeln(mask==1);
list=unique(p)';list(1)=[];
figure('color','w');
hold on
for i=list
f=double(r.img).*repmat(p==i,[1,1,1,size(image,4)]);
y=sum(sum(nansum(f,1),2),3);y=y/sum(sum(sum(p==i)));
pv=sum(sum(sum(p==i)));
plot(y(:),'x-','color', 'blue');
plot(movmean(y(:),20),'r-','linewidth',1);
end
I tried something like the following unfortunately without success. I would appreciate any help.
image = My 4D image;
mask = My 3D mask;
p=bwlabeln(mask==1);
list=unique(p)';list(1)=[];
figure('color','w');
hold on
for i=list
f=double(r.img).*repmat(p==i,[1,1,1,size(image,4)]);
y=sum(sum(nansum(f,1),2),3);y=y/sum(sum(sum(p==i)));
pv=sum(sum(sum(p==i)));
plot(y(:),'x-','color', 'blue');
plot(movmean(y(:),20),'r-','linewidth',1);
%Trying here to store the data of each iteration and calculate the
%average
z = y(i) + y(i+1) + y(i+2)
z = z / size(list,2)
end

回答(1 个)

KSSV
KSSV 2022-2-17
yy = cell(length(list),1) ;
p=bwlabeln(mask==1);
list=unique(p)';list(1)=[];
figure('color','w');
hold on
for i=list
f=double(r.img).*repmat(p==i,[1,1,1,size(image,4)]);
y=sum(sum(nansum(f,1),2),3);y=y/sum(sum(sum(p==i)));
pv=sum(sum(sum(p==i)));
plot(y(:),'x-','color', 'blue');
plot(movmean(y(:),20),'r-','linewidth',1);
yy{i} = y(:) ; % hop i is an integer
end

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by