how do we plot enumerated data and real floating point data in the same plot/figure?
63 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
DJ Regan
el 10 de En. de 2020
Respondida: Devineni Aslesha
el 13 de En. de 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 comentarios
Respuesta aceptada
Devineni Aslesha
el 13 de En. de 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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Annotations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!