1. 程式人生 > >MATLAB plot多條曲線

MATLAB plot多條曲線

轉載自:http://blog.sina.com.cn/s/blog_618af1950100pmnf.html

Matlab 提供了幾種線型?4種



Matlab提供了幾種Marker?10幾種


每次畫曲線都要想要用那種線型,很麻煩,可以寫個函式,把所有的線型,marker什麼的資訊都輸出。
function [linestyles,MarkerEdgeColors,Markers]= generate_line_styles(n)
% generate the space of linestyles, MarkerEdgeColors,Markers
basic_linestyles = cellstr(char('-',':','-.','--'));

basic_Markers    = cellstr(char('o','x','+','*','s','d','v','^','<','>','p','h','.'));
MarkerEdgeColors = jet(n);
linestyles       = repmat(basic_linestyles,ceil(n/4),1);
Markers          = repmat(basic_Markers,ceil(n/13),1);
end

這樣要畫曲線時,呼叫函式 [linestyles,MarkerEdgeColors,Markers]= generate_line_styles(n)
獲得你可以使用的線型,顏色還有標記。
舉例如下:
z=peaks;
plot(z);
matlab自動為每條曲線分配顏色。


%呼叫generate_line_styles函式
n=length(z);
[linestyles,MarkerEdgeColors,Markers]=generate_line_styles(n);

figure;

for i=1:n

 plot(z(i,:),[linestyles{i} Markers{i}],'Color',MarkerEdgeColors(i,:));

    hold on

end
%使用不用線型,不同標記,不同顏色,效果如下


figure;
for i=1:n

 plot(z(i,:),[linestyles{i}],'Color',MarkerEdgeColors(i,:));

    hold on

end
%使用不用線型,不同顏色,效果如下

figure;
for i=1:n
 plot(z(i,:),'Color',MarkerEdgeColors(i,:));

    hold on

end

%僅使用不同顏色,效果如下:


哪種效果更好呢?