Reputation: 5541
I am attempting to make lines more easily distinguishable by changing the line styes. However, most of the style changes are being ignored by matlab for no apparent reason. As far as I can tell, only ':'
is being acknowledged and shown; everything else just uses a solid line regardless of what I put in. Can anyone explain why this is happening and give a method for making matlab actually change the lines?
hold on;
style = ['-','--',':','-.'];
...
for q = 1:length(names)
... %generate data, etc.
plot_lines(q)=plot(ttt,aclatn,'Color',colors(q,:),'LineStyle',style(1+int8(mod(q,4))),'DisplayName',strcat(num2str(d),'cm'));
end
Upvotes: 2
Views: 207
Reputation: 13945
You need to enclose the line styles in a cell array and access them using {curly braces}. Otherwise Matlab sees your array as one big character array like so:
style =
---:-.
and tries to assign '-'
as a LineStyle
property 4 times out of 6, which does not work.
However using
style = {'-','--',':','-.'}
to define the styles and
style{1+int8(mod(q,4))}
to access them works fine.
Example:
clear
clc
hold on;
style = {'-','--',':','-.'};
ttt = 1:10;
for q = 1:4
aclatn = rand(1,10);
plot_lines(q)=plot(ttt,aclatn,'LineStyle',style{1+int8(mod(q,4))});
end
Output:
Yay!
Upvotes: 2