How to store data in each iteration

3 visualizzazioni (ultimi 30 giorni)
DM
DM il 17 Feb 2022
Risposto: KSSV il 17 Feb 2022
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

Risposte (1)

KSSV
KSSV il 17 Feb 2022
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

Community Treasure Hunt

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

Start Hunting!

Translated by