Designate order of categorical array?
8 views (last 30 days)
Show older comments
I have a categorical array that I'm plotting on the y-axis against time. I need to designate that E_1 is greater than E_2, but it keeps plotting E_1 as the lower y-value. I tried the reverse function: ay.YAxis.Direction = 'reverse' but it doesn't seem to apply to categorical arrays.
y= ["E_1","E_1","E_2","E_2","E_2","E_2","E_2"] %y-values
y1 = categorical(y) %designate as categorical array
x= [-0.2, 0, 0.002, 0.01, 0.05, 0.25, 1] %x-values
plot(x,y1,'k',"LineWidth",1.5) %plot
0 Comments
Accepted Answer
dpb
on 7 Jun 2021
You have to create an ordinal categorical array of the desired ordering of magnitudes to force other than the alphabetic ordering MATLAB uses by default.
valueset=fliplr(unique(y)); % generate order of values reverse alpha order
yOrd=categorical(y,valueset,'Ordinal',true); % create ordinal categorical with those values
Now the plot of yOrd versus x will have E1 above E2 on the y-axis.
2 Comments
More Answers (0)
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!