Thread Subject: Help with plot and linespec matrix

Subject: Help with plot and linespec matrix

From: Kevin

Date: 4 Nov, 2009 18:39:04

Message: 1 of 1

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');

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
vector Kevin 4 Nov, 2009 13:44:06
linespec Kevin 4 Nov, 2009 13:44:06
matrix Kevin 4 Nov, 2009 13:44:06
plot Kevin 4 Nov, 2009 13:44:04
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com