Effacer les filtres
Effacer les filtres

Write code for a given plot

10 vues (au cours des 30 derniers jours)
Dobs
Dobs le 22 Nov 2021
Commenté : Dobs le 22 Nov 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.

Réponse acceptée

DGM
DGM le 22 Nov 2021
Modifié(e) : DGM le 22 Nov 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 commentaire
Dobs
Dobs le 22 Nov 2021
Yes, that's great, thank you so much!

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by