Storing matrices from a loop in an array
Show older comments
My program takes a 3D matrix and creates as many 2D matrices as the size of the third dimension. This matrices are later represented as images. The problem is my code isn't really storing this matrices but overwriting them everytime. I need to store them in another array. I also need to store only those matrices that are not made up of only zero values. I have successfully obtained the number of only-zero matrices but I haven't succeeded in storing them. What is the best way to do this?
n=1;
for s=1:d3
thisimage=MA(:,:,s);
%counts how many matrices have only zero values
if sum(thisimage)==0
n=n+1;
end
% create a new matrix, size, minus the zero only matrices
%store non zero matrices in this vector
t=cell(d3-n);
if sum(thisimage)~=0
t(s)=thisimage;
end
subplot(12,17,s),subimage(thisimage);figure(gcf)
axis off
colormap(gray);
%%Draw only every five images
s=s+5;
end
Thank you for your help
Accepted Answer
More Answers (0)
Categories
Find more on Image Arithmetic in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!