Different line types for multiple curves
    2 views (last 30 days)
  
       Show older comments
    
    Kenneth Bisgaard Cristensen
 on 9 Apr 2021
  
    
    
    
    
    Commented: Kenneth Bisgaard Cristensen
 on 9 Apr 2021
            Hi MATLAB Community,
How would I change the line type for my plot, so I have a '-r' and '--r' as well as '-b' and '--b'?
figure;
p = plot(x, y);
set(p, {'color'}, {'r'; 'r'; 'b'; 'b'});
0 Comments
Accepted Answer
  Bjorn Gustavsson
      
 on 9 Apr 2021
        Maybe you'll have to accept looping a little:
lstl = {'-','--'};
for i1 = 1:4,
  set(p(i1),'linestyle',lstl{rem(i1,2)+1})
end
HTH
More Answers (1)
  VBBV
      
      
 on 9 Apr 2021
        
      Edited: VBBV
      
      
 on 9 Apr 2021
  
      %f true
  figure;
p = plot(x, y);
set(p, {'LineStyle'},{'-';'--';'-';'--'},{'color'}, {'r'; 'r'; 'b'; 'b'});
1 Comment
  Bjorn Gustavsson
      
 on 9 Apr 2021
				Neat, but:
Mathworks, this is ugly!
When I tried this:
set(p, 'LineStyle',{'-';'--';'-';'--'},{'color'}, {'r'; 'r'; 'b'; 'b'});  
I got and angry error-message:
Error using matlab.graphics.chart.primitive.Line/set
Error setting property 'LineStyle' of class 'Line':
Invalid enum value. Use one of these values: '-' | '--' | ':' | '-.' | 'none'. 
...but when wrapping the property in a cell-array everything works fine. That is ugly.
See Also
Categories
				Find more on Introduction to Installation and Licensing 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!

