How do I use custom line styles within MATLAB?
38 views (last 30 days)
Show older comments
In other programs, the most common extra line style is a dash-dot-dot line. Other line styles that are available are a dash-dot-dot-dot line, a long dash line, a short dash line (may look similar to the dotted line in MATLAB depending on renderer settings), a short dash-dot line, a long dash-dot line, and more widely or closely spaced dash lines.
Accepted Answer
MathWorks Support Team
on 2 Sep 2010
There are only four line styles available in MATLAB: 'solid', 'dotted', 'dashdot', and 'dashed'. For more information on available line styles colors and symbols type:
doc plot
at the MATLAB command prompt.
To work around this issue you can use traditional plotting techniques in MATLAB to simulate, for example, a '|' linestyle.
Here is an example which takes two vectors, "x" and "y", and reformats them so that a simple plot statement will generate a '|' graph. The example inserts 2 new elements between each original element of the old vector. Then, NaN values are inserted into both "x" and "y "to create a break in the data set. Next, a small increment "y + a" is inserted into the new "y" matrix to give each point height.
function h = plotbar(x,y)
%PLOTBAR Plot two vectors simulating a '|' linestyle
% h = plotbar(x,y) returns a handle to the line created.
x = x(:);
y = y(:);
newx = zeros(1,length(x)*3);
newx(1:3:end) = x;
newx(2:3:end) = x;
newx(3:3:end) = nan;
newy = zeros(1,length(y)*3);
newy(1:3:end) = y;
newy(2:3:end) = y+((max(y)-min(y))/20);
newy(3:3:end) = nan;
h = plot(newx,newy);
Here are some examples of the use of this function:
plotbar(1:10,1:10);
plotbar(rand(10),rand(10));
plotbar(magic(5),inv(magic(5)));
0 Comments
More Answers (0)
See Also
Categories
Find more on Line Plots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!