Bargraph based on cell-array with two columns

'AK' 11788
'AZ' 19747
'CA' 19553
'ID' 6762
'ME' 39108
'MI' 10372
'MN' 23693
'MT' 38930
'ND' 58290
'NM' 6615
'NY' 21323
'OH' 10
'TX' 36758
'VT' 16727
'WA' 45836
I have the above cell array, called "out". I'm trying to simply graph column 1 on the X-axis, and column 2 on the Y-axis. I feel it shouldn't be such a hard task, but I've looked around and all the posts I've found error out, such as "bar(categorical(out{1:15, 1}), out{1:15, 2});" which yields "Error using categorical (line 251) Invalid parameter name: AZ."
Any help would be appreciated!

Respuestas (1)

Adam Danz
Adam Danz el 22 de Jun. de 2020
Editada: Adam Danz el 23 de Jun. de 2020
Assuming your cell array is named data where the first the first column are the labels and the second column are the bar heights,
h = bar([data{:,2}]);
set(h(1).Parent, 'XTick', 1:size(data,1), 'XTickLabel', data(:,1))

Categorías

Más información sobre MATLAB en Centro de ayuda y File Exchange.

Productos

Versión

R2017b

Etiquetas

Preguntada:

el 22 de Jun. de 2020

Editada:

el 23 de Jun. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by