how do we plot enumerated data and real floating point data in the same plot/figure?
68 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
DJ Regan
il 10 Gen 2020
Risposto: Devineni Aslesha
il 13 Gen 2020
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?
0 Commenti
Risposta accettata
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.
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Annotations 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!