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 Center および File ExchangeImage Processing Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by