Effacer les filtres
Effacer les filtres

sorting skalars and string

1 vue (au cours des 30 derniers jours)
Ariela Glikman
Ariela Glikman le 29 Déc 2018
Modifié(e) : per isakson le 29 Déc 2018
hi,
i have cell array with strings and skalars name : 'hun.mat'
this is the cell:
hun= {'chocolate',40,'strawberry jam',50,'dulce de leche',45,'halva',60};
who contains the number of doughnuts that were made for each type of doughnuts .
I neet to Create a 4x2 cell array called ‘monitorData’ that includes in each row the name of the type of each doughnut type (string) (in the first column), and the percent of doughnuts that were bought from the total number that were made for each type (scalar) (in the second column).

Réponses (1)

per isakson
per isakson le 29 Déc 2018
Modifié(e) : per isakson le 29 Déc 2018
The first step
>> monitorData = permute( reshape( hun, 2,[] ), [2,1] );
>> monitorData
monitorData =
4×2 cell array
{'chocolate' } {[40]}
{'strawberry jam'} {[50]}
{'dulce de leche'} {[45]}
{'halva' } {[60]}
without comments and the final step
>> s = sum([monitorData{:,2}])
s =
195
>> monitorData(:,2) = cellfun( @(n) 100*n/s, monitorData(:,2), 'uni',false )
monitorData =
4×2 cell array
{'chocolate' } {[20.5128]}
{'strawberry jam'} {[25.6410]}
{'dulce de leche'} {[23.0769]}
{'halva' } {[30.7692]}

Catégories

En savoir plus sur Data Type Conversion dans Help Center et File Exchange

Produits


Version

R2016a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by