how do we plot enumerated data and real floating point data in the same plot/figure?

81 views (last 30 days)
Using the plot command...
How do we plot enumerated values along side real floating point data values within the same plot/figure?
Are there examples on the MathWorks web site? We can use the yyaxis left/right commands to create plots with multiple scales... such as...
...but, can one of them be a value with enumerated states data type?

Accepted Answer

Devineni Aslesha
Devineni Aslesha on 13 Jan 2020
The y-axis values in the plot function do not support enumerated data types. Refer https://www.mathworks.com/help/matlab/ref/plot.html for more information.
However, this can be made possible by using the yticklabels function in matlab. The enumerated data types can be defined by defining the class ‘BasicColors’ as follows.
classdefBasicColors < Simulink.IntEnumType
enumeration
Red(0)
Yellow(1)
Green(2)
end
end
Save the class as BasicColors.m file. Use the defined class in the below code to plot the enumerated data type along with the real floating point data type.
x = [1 2 3];
[~,y] = enumeration('BasicColors');
z = [25.2 25.9 67.9];
yticklabels(y)
yticks([0 1 2]);
ylim([0 2]);
yyaxis right;
plot(x, z);
Refer the following links for more information.

More Answers (0)

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!