Hello every one
I have an assignment,PLEASE , I need to draw a group of points
(x,y1) in red colour
(x,y2) in blue colour
(x,y3) in green
(x,y4) in pink
(x,y5) in yallow
at the same time in the form of specifying their points only and in different colors to distinguish them and with the extension of certain numbers to the x-axis shown in the picture
I drew the points in Excel, but the only error in the drawing is the presence of a straight line connecting the points, and this is not what I want. In addition, in Excel, I cannot enlarge the drawing, nor can I show a clearer picture of the points that contain 0.000, the points appear as on the zero axis, which they are not
I searched a lot with Matlab commands in drawing and found it
scatter(x,y1,'ro') ...
I used it in the attached file, but the output of the drawing is not in the description I mentioned above
is possible to plot in matlab ??
if any prof can help me thanks alot.

 採用された回答

Jan
Jan 2022 年 3 月 6 日
編集済み: Jan 2022 年 3 月 6 日

0 投票

scatter() is a "high-level" function for drawing. Such functions clear the contents of the axes automatically. To collect the output, use hold on or equivalently:
axes('nextplot', 'add'); % equivalent to: hold on
% Then let the drawing follow:
scatter(x,y1,'ro')
scatter(x,y2,'b*')
scatter(x,y3,'g')
scatter(x,y4,'p')
scatter(x,y5,'y')

9 件のコメント

hasan s
hasan s 2022 年 3 月 6 日
編集済み: hasan s 2022 年 3 月 6 日
thanks prof. Jan for your help
but I need x-axes as
1 2 3 4 10 1 2 3 4 10 1 2 3 4 10
is there possible to add tool to draw that
hasan s
hasan s 2022 年 3 月 8 日
thank you very much prof Jan
I really benefited from your answer... thanks alot
Jan
Jan 2022 年 3 月 8 日
I'm glad, if I can help.
What does "x-axes as 1 2 3 4 10 1 2 3 4 10 1 2 3 4 10" mean? I'm not sure, how this should look like.
hasan s
hasan s 2022 年 3 月 8 日
The drawing required of me should appear as in the first attached image of the Excel program, but without a straight line connecting the points.
therefore ... I had to repeat the drawing, and it became several drawings instead of what was required of me as one drawing on an x-axis
Thank you so much prof. Jan
Jan
Jan 2022 年 3 月 8 日
Perhaps this helps:
data = rand(1, 10);
plot(1:10, data, 'rx')
hold on
plot(1:10, 1-data, 'bo')
hasan s
hasan s 2022 年 3 月 8 日
編集済み: hasan s 2022 年 3 月 8 日
thanks alot prof. Jan
but x-axis is still 1 2 ... 10
I need x axis as 1 2 ... 10 1 2 ... 10 1 2 .... 10 with their graph
It's like after I start drawing (x, y1) from x=1 ... 10, after 10 start the new count from x=1 ...10 , in order to start drawing (x, y2)
I will try in Your last idea..I'm trying to understand it
thank you very very much
Jan
Jan 2022 年 3 月 8 日
I still do not understand, what this means: "x axis as 1 2 ... 10 1 2 ... 10 1 2 .... 10 with their graph"
Maybe:
axes('XLim', [1, 15], ...
'Xtick', 1:15, ...
'XTickLabel', sprintfc('%d', [1 2 3 4 10]))
If there are more ticks than labels, the labels are repeated.
hasan s
hasan s 2022 年 3 月 8 日
Excellent programming , thanks alot prof. Jan
This is what I want
Now I have to understand How do I add the commands to get the drawing...
hasan s
hasan s 2022 年 3 月 8 日
Thank you very much for your help

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

その他の回答 (1 件)

Les Beckham
Les Beckham 2022 年 3 月 8 日
編集済み: Les Beckham 2022 年 3 月 8 日

1 投票

It isn't pretty but this is the closest I could come up with to reproducing what you appear to want.
x =[ 1 2 3 4 10 1 2 3 4 10 1 2 3 4 10 ];
y1=[ 2 1 5 3 1 0.2 0.1 0.5 0.3 0.1 2.00E-03 1.00E-03 5.00E-03 3.00E-03 1.00E-03 ];
y2=[ 4 3 7 4 4 0.4 0.3 0.7 0.4 0.4 4.00E-03 3.00E-03 7.00E-03 4.00E-03 4.00E-03 ];
y3=[ 6 5 8 7 6 0.6 0.5 0.8 0.7 0.6 6.00E-03 5.00E-03 8.00E-03 7.00E-03 6.00E-03 ];
y4=[ 5 4 8 5 5 0.4 0.3 0.7 0.4 0.4 4.00E-03 3.00E-03 7.00E-03 4.00E-03 4.00E-03 ];
y5=[ 6 6 9 8 7 0.6 0.5 0.8 0.7 0.6 6.00E-03 5.00E-03 8.00E-03 7.00E-03 6.00E-03 ];
figure(1)
plot(1:15, y1, 'x', 1:15, y2, 'sq', 1:15, y3, '^', 1:15, y4, '+', 1:15, y5, 'o');
xticks(1:15)
xticklabels({'1' '2' '3' '4' '10' '1' '2' '3' '4' '10' '1' '2' '3' '4' '10'})
grid on
I think it looks better with the lines.
figure(2)
plot(1:15, y1, 'x-', 1:15, y2, 'sq-', 1:15, y3, '^-', 1:15, y4, '+-', 1:15, y5, 'o-');
xticks(1:15)
xticklabels({'1' '2' '3' '4' '10' '1' '2' '3' '4' '10' '1' '2' '3' '4' '10'})
grid on

2 件のコメント

hasan s
hasan s 2022 年 3 月 8 日
Excellent programming too
This is exactly what I need
Thank you very much prof. Les Beckham for your help
Les Beckham
Les Beckham 2022 年 3 月 8 日
You are quite welcome.

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

カテゴリ

ヘルプ センター および File ExchangeData Exploration についてさらに検索

タグ

質問済み:

2022 年 3 月 6 日

コメント済み:

2022 年 3 月 8 日

Community Treasure Hunt

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

Start Hunting!

Translated by