Selecting categorical variable range to plot on bar graph

6 views (last 30 days)
Nex
Nex on 29 Sep 2021
Commented: Nex on 4 Oct 2021
I don't understand why the categorical data is shown in its entirety on the graph despite only a portion of it being selected.
Am I indexing it wrongly?
C = categorical({'A'; 'B'; 'C'; 'D'; 'E'; 'F'});
N = [5 4 2 3 4 8];
bar(C(3:end), N(3:end))
  2 Comments
Nex
Nex on 4 Oct 2021
Thank you very much for the clear explanation and suggestion of a solution.

Sign in to comment.

Accepted Answer

VBBV
VBBV on 29 Sep 2021
C = categorical({'A'; 'B'; 'C'; 'D'; 'E'; 'F'});
N = [5 4 2 3 4 8];
bar(C(3:end), N(3:end))
xticks(C(3:end))
xticklabels(C(3:end))
Use Xticks & Xticklabels

More Answers (0)

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!