0
votes

In matlab you can use plot() with matrix input, which is very fast and convenient. However, when I try and spec the lines I cannot find a way. I am stuck decomposing what I have then feeding each portion a spec rather painstakingly.

Example :

clear; clc;

x = [1 2 3;
     4 5 6;
     7 8 9];
y = [1 4 7;
     2 5 8;
     3 6 9];

 subplot(2,1,1)
 plot(x,y)

 subplot(2,1,2)
 plot(x(:,1),y(:,1),':.',...
 x(:,2),y(:,2),'--',...
 x(:,3),y(:,3),':.b')

How can I spec subplot one without decomposing it like in subplot 2?

1

1 Answers

2
votes

You can set the properties individually using the line handles/objects returned by plot. If you are using Matlab R2014b or newer, a line object array is returned and can be manipulated using dot-notation:

 h = plot(x,y);
 %
 h(1).LineStyle = ':';
 h(1).Marker    = '.';
 %
 h(2).LineStyle = '--';
 %
 h(3).Color     = 'b';
 h(3).LineStyle = ':';
 h(3).Marker    = '.';

For older versions that return a line handle array, you can directly set the values either one at a time:

h = plot(x,y);
set(h(1),'LineStyle',':','Marker','.');
set(h(2),'LineStyle','--');
set(h(3),'Color','b','LineStyle',':','Marker','.');

or all at once using name and value arrays

 h = plot(x,y);
names = {'LineStyle','Marker','Color'};
values = {
    ':'  , '.'    , get(h(1),'Color');
    '--' , 'none' , get(h(2),'Color');
    ':'  , '.'    , 'b'
    };
set(h,names,values);

Note that all of the set solutions also work in R2014+ versions.