Re-hash the intrinsic Matlab plot function to accept a string as a y input?
1 view (last 30 days)
Show older comments
I am using the matlab 'plot' function which uses x, y as inputs. The x axis is time (which is a number in seconds and is easy), however the y axis is actually a number/string combination, for example, E312, E313. The plot function breaks since it is only expecting a numeric value, however I want the ylabel (for that corresponding point) to display 'E312' (in this example); how is that possibe?
2 Comments
Walter Roberson
on 17 Apr 2019
If I have (say) 500 pixels available for y axes, then how far up should 'E312' appear? How far up should 'E313' appear? Is 'E1000' above or below 'E2' ?
Answers (1)
Steven Lord
on 17 Apr 2019
You could turn your text data into a categorical array then plot with that categorical data as the Y input.
colors = categorical({'r' 'b' 'g', 'g' 'r' 'b', 'b' 'r' 'g'}, ...
{'r' 'g' 'b'},{'red' 'green' 'blue'});
plot(1:9, colors)
Alternately, if you want to plot numeric data and just have the labels on the axes change, use the yticklabels function.
1 Comment
See Also
Categories
Find more on Line 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!