Write code for a given plot

3 ビュー (過去 30 日間)
Dobs
Dobs 2021 年 11 月 22 日
コメント済み: Dobs 2021 年 11 月 22 日
Hi,
we're supposed to write the code for the plot in the attached image. So far I have the following code but the plot doesn't look like the one in the image:
x = linspace(0, 100);
y = linspace(0, 50);
a = linspace(0, 100);
b = linspace(50, 0);
P = figure;
hold on;
p1 = plot(a, b, 's');
p2 = plot(x, y, 's');
ylabel('amplitude');
xlabel('time');
p1.MarkerIndices = 1:10:length(x);
p2.MarkerIndices = 1:10:length(x);
p1.MarkerFaceColor = 'blue';
p1.Color = 'blue';
The first problem is that the line disappeared when I added the markers via MarkerIndices. The second problem is that the markers are not in the same spots as the ones in the attached image.
Does anybody have any ideas what I'm doing wrong and what I should do differently?
Many thanks,
Dobs
P.S. We're supposed to use handles to change the appearance of the plot.

採用された回答

DGM
DGM 2021 年 11 月 22 日
編集済み: DGM 2021 年 11 月 22 日
Something like this
% points don't need to be any more dense than the marker spacing
% so we really only need one set
x = linspace(0,100,10);
y = linspace(0,50,10);
P = figure(1);
hold on;
p1 = plot(x, 50-y, '-ob'); % blue, round markers, with line
p2 = plot(x, y, '-sr'); % red, square markers, with line
ylabel('amplitude');
xlabel('time');
p1.MarkerFaceColor = 'blue'; % filled face
p1.LineWidth = 2; % heavier line
  1 件のコメント
Dobs
Dobs 2021 年 11 月 22 日
Yes, that's great, thank you so much!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by