Azzera filtri
Azzera filtri

Group bar graph, with different group sizes?

16 visualizzazioni (ultimi 30 giorni)
Tracy Campbell
Tracy Campbell il 12 Dic 2017
Risposto: Chris Perkins il 14 Dic 2017
Hi all,
I'm trying to make a bar graph with groups - but not all groups are the same size.
My current code is as follows:
y = [13.2764279; -2.011230558 5.146663618 5.7332464; -22.2335537 -5.60238553 -4.9771596; -47.575537 -18.405 -23.2868517];
figure1=figure;
bar(y)
xticklabels({'Baseline';'10% Perennials, 10% Reduction'; '10% Perennials, No reduction'; 'No increase, 10% Reduction';'25% Perennials, 25% Reduction'; '25% Perennials, No reduction'; 'No increase, 25% Reduction';'50% Perennials, 50% Reduction'; '50% Perennials, No reduction'; 'No increase, 50% Reduction'});
xtickangle(45)
xticks(1:1:length(category))
Besides adding in 0 or NaN - are there any other options? Thanks for the help!

Risposte (1)

Chris Perkins
Chris Perkins il 14 Dic 2017
Hi Tracy,
As a matrix in MATLAB cannot have a different number of columns per row, you will have to pad any rows that are not full length (in your example, only row 1) with NaN or 0, as you mention in your post.

Categorie

Scopri di più su Dialog Boxes in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by