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