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

68 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Devineni Aslesha
Devineni Aslesha il 13 Gen 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.

Più risposte (0)

Prodotti


Release

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by