Write code for a given plot

7 visualizaciones (últimos 30 días)
Dobs
Dobs el 22 de Nov. de 2021
Comentada: Dobs el 22 de Nov. de 2021
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.

Respuesta aceptada

DGM
DGM el 22 de Nov. de 2021
Editada: DGM el 22 de Nov. de 2021
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 comentario
Dobs
Dobs el 22 de Nov. de 2021
Yes, that's great, thank you so much!

Iniciar sesión para comentar.

Más respuestas (0)

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by