How to plot two independent curves as symbols in one graph?

3 ビュー (過去 30 日間)
Emerson De Souza
Emerson De Souza 2012 年 9 月 23 日
GOAL: I have two independent arrays y1 and y2 and want to plot them depending on x1 and x2 in the same graph. The curves should be plotted as symbols and not as lines. I wrote the following lines:
X1=[1:99,1]';
X2=[1:199,1];
Y1=rand(100,1);
Y2=rand(200,1)*-1;
h=plot(X1,Y1,X2,Y2);
axis([0 200 -1 1])
%Curve Properties
set(h,{'Color'},{'r';'g'})
set(h,{'LineStyle'},{'s';'v'})
set(h,{'MarkerSize'},{4;4})
PROBLEM: Unfortunately, the curves are not plotted as symbols and the colors are not accepted also. I obtain the following error:
Error using set
Value cell array handle dimension must match handle vector length
I read the instructions to use "set" but did not understand how to correct the command lines. I wonder if someone could help me to fix this.
Thank you in advance for your attention
Emerson

採用された回答

Wayne King
Wayne King 2012 年 9 月 23 日
編集済み: Wayne King 2012 年 9 月 23 日
I don't have any problem with your code, what version of MATLAB are you using? Do these work for you?
X1 = [1:99,1]';
X2 = [1:199,1];
Y1 = rand(100,1);
Y2 = rand(200,1)*-1;
plot(X1,Y1,'rs','markersize',4); hold on;
plot(X2,Y2,'gv','markersize',4)
axis([0 200 -1 1])
Another way:
X1 =[1:99,1]';
X2 =[1:199,1];
Y1 = rand(100,1);
Y2 = rand(200,1)*-1;
h = plot(X1,Y1,X2,Y2);
axis([0 200 -1 1])
set(h(1),'color','r','linestyle','s','markersize',4);
set(h(2),'color','g','linestyle','v','markersize',4);
  3 件のコメント
Wayne King
Wayne King 2012 年 9 月 23 日
I don't have any problem with your initial code with just two. What version are you using?
Emerson De Souza
Emerson De Souza 2012 年 9 月 23 日
編集済み: Emerson De Souza 2012 年 9 月 23 日
Interesting, I use R2012a, and now it is working also. It may have happened that I accidentally removed the comment % from the line Curve Properties. I tried this and the plot is executed but with the error above. I'm very sorry and thank you a lot for your help. Wish you a nice day
Emerson

サインインしてコメントする。

その他の回答 (0 件)

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by