Write code for a given plot

30 次查看(过去 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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by