Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Help with plot and linespec matrix
Date: Wed, 4 Nov 2009 18:39:04 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 35
Message-ID: <hcsho8$ps4$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1257359944 26500 172.30.248.35 (4 Nov 2009 18:39:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 4 Nov 2009 18:39:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2012741
Xref: news.mathworks.com comp.soft-sys.matlab:582476


Hi all,
I'm trying to make a single plot with a single dependent variable and multiple functions and include a linespec matrix or vector to change the linetype for each line. Matlab already changes the color but, for easy differentiation after printing in black and white, I want to change whether the line is solid or dashed or dotted.

I'm including sample code that creates the kind of plot I want. The problem is that there was a bit of hacking I found on Google to get that done, and I think there might be a more straight-forward and easily expandable way that would look like:

plot(theta,out,my_lines);

Where theta is an angle vector, out is a matrix of results, and my_lines would be some kind of linespec matrix.

Any thoughts would be appreciated!

Sample code:
close all; clear all;

theta = 0:360;
phase = [0;120;240];

out = zeros(length(phase),length(theta));

for i = 1:length(phase)
    out(i,:) = sind(theta+phase(i));
end

scrsz = get(0,'ScreenSize');% size plots to match sreen

figure('Position',[0.1*scrsz(3) 0.1*scrsz(4) 0.5*scrsz(3) 0.8*scrsz(4)]);
foo = plot(theta,out);
set(foo(2),'linestyle',':');
set(foo(3),'linestyle','--');
legend(['\theta_{p1} = ' num2str(phase(1)) '?'],...
    ['\theta_{p2} = ' num2str(phase(2)) '?'],...
    ['\theta_{p3} = ' num2str(phase(3)) '?']);
title('Sine waves with phase angles \theta_{pi}');
xlabel('\theta'); ylabel('sin(\theta + \theta_{pi})');
%saveas(gcf,'output.pdf');