Monday, March 05, 2007

[Matlab] Plot lines with different markers

Source

Matlab Help:
  • Find "LineSpec" to see the available markers

Codes

% Initialize a set of desired markers
MarkerSet = 'x*o+s.^v';
plot( x, y ); grid on;
% Obtain all line handles under current axes handle
hdl = findobj(gca,'Type','line');
for k=1:length(hdl)
% Assign markers to each line handle
set(hdl(k), 'marker', MarkerSet(k) );
end

[Matlab] Plotyy and the Labeling

Source:

Matlab Help

Codes:

MY_XLABEL = 'This is xlabel';
MY_Y1LABEL = 'This is y1 label';
MY_Y2LABEL = 'This is y2 label';
MY_Y1LEGEND = {'y1_lg1', 'y1_lg2' };
MY_Y2LEGEND = {'y2_lg1', 'y2_lg2' };
MY_TITLE = 'This is my title';

[AX,H1,H2] = plotyy(x1, y1, x2, y2);
xlabel( MY_XLABEL );
set(get(AX(1),'Ylabel'),'String', MY_Y1LABEL );
set(get(AX(2),'Ylabel'),'String', MY_Y2LABEL );
legend(H1, MY_Y1LEGEND, 'Location', 'NorthWest' );
legend(H2, MY_Y2LEGEND, 'Location', 'NorthEast' );
title( MY_TITLE );