2013-05-10 93 views
0

無論如何,我希望在二維圖(x和y)上繪製兩個列向量,其中填充了無負數的隨機數。 'x向量'我可以保持原樣,但是使用'y向量'時,我希望將任何等於零的y值作爲不同的顏色(表示紅色)與其他正值非零值(說藍色)。繪製兩種不同顏色的MATLAB值

如果可能的話,請儘量保持解決方案相對簡單,因爲我自己對MATLAB以及本站比較陌生。

回答

0

我不確定你的意思是二維圖,但我假設你的意思只是一個正常的曲線。試試這個:

x = rand(10, 1); 
y = rand(10, 1); 

y([5 8]) = 0; %Force a couple of values to be 0 for visualisation 

t = 1:10;  

plot(t, x); 
hold on 
plot(t, y, 'g'); 
ind = y == 0; %Make a logical index that masks all the value where y is not 0 
plot(t(ind), y(ind), 'r*'); 

enter image description here

+0

不完全是圖我一直在尋找,但劇本是很容易理解和提供我要我寫我的一個很好的基礎。所以謝謝。 – Sig 2013-05-10 12:54:46

相關問題