How to convert 2D array to a comma separated list of array

3 views (last 30 days)
regions = regionprops(label, image(:,:,1), 'Centroid');
regions(:).Centroid gives me a comma-separated-lists of vectors. How can I convert a 2D array into a comma-separated-list-of-vectors ? Below example I want to concatenate mean rgb data into region(:).MeanIntensity
r_data = regionprops(label, image(:,:,1), 'PixelValues', 'MeanIntensity');
g_data = regionprops(label, image(:,:,2), 'PixelValues', 'MeanIntensity');
b_data = regionprops(label, image(:,:,3), 'PixelValues', 'MeanIntensity');
I went to concatenate the data to get a 100 x 3 matrix
rgb = [vertcat(r_data(:).MeanIntensity), vertcat(g_data.MeanIntensity), vertcat(b_data.MeanIntensity)]
Now my task is to figure out how to push this into regions(:).RGB. Why does this not work ?
regions(:).MeanIntensity = [rgb(:,1), rgb(:,2), rgb(:,3)];
How do I tell Matlab to convert my 2D array of 100x3 into a comma separated list of vector

Accepted Answer

Walter Roberson
Walter Roberson on 17 Jan 2017
rgbcell = mat2cell(rgb, ones(1, size(rgb,1)), size(rgb,2));
[regions(:).MeanIntensity] = rgbcell{:};

More Answers (0)

Categories

Find more on Resizing and Reshaping Matrices 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!