How to convert 2D array to a comma separated list of array
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
RuiQi
le 17 Jan 2017
Réponse apportée : Walter Roberson
le 17 Jan 2017
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 commentaires
Réponse acceptée
Walter Roberson
le 17 Jan 2017
rgbcell = mat2cell(rgb, ones(1, size(rgb,1)), size(rgb,2));
[regions(:).MeanIntensity] = rgbcell{:};
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!