필터 지우기
필터 지우기

Write code for a given plot

조회 수: 10 (최근 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 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