Vitor Rangel
Vitor Rangel

Reputation: 363

It's possible to do a array of Matrix in Matlab?

I'm doing a project in a University here in Brasil, and I'm using MatLab. I'm new in it, so I have to search a lot. A problem that's disturbing me right now is that I need to store many Matrix of different sizes in a Array. The code is:

for count = 1:nColors
i = rgb2gray(segmented_images(:,:,:,count));
bw = im2bw(i,0.01);
s = regionprops(bw,'Centroid');
centroids = cat(1, s.Centroid);
end

Centroids is a Matrix, and the size of it varies. I need to store it, so I can use later. I tried

centroids(count) = cat(1, s.Centroid);

but MatLab said "In an assignment A(I) = B, the number of elements in B and I must be the same."

Upvotes: 0

Views: 220

Answers (2)

Don Gorgon
Don Gorgon

Reputation: 2601

for count = 1:nColors
i = rgb2gray(segmented_images(:,:,:,count));
bw = im2bw(i,0.01);
s = regionprops(bw,'Centroid');
centroids(i).matrix = cat(1, s.Centroid);
end

Upvotes: 1

Nzbuu
Nzbuu

Reputation: 5251

You need a cell array: http://www.mathworks.co.uk/help/techdoc/matlab_prog/br04bw6-98.html

Upvotes: 1

Related Questions