How to convert 2D array to a comma separated list of array
3 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Walter Roberson
2017-1-17
rgbcell = mat2cell(rgb, ones(1, size(rgb,1)), size(rgb,2));
[regions(:).MeanIntensity] = rgbcell{:};
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!