Effacer les filtres
Effacer les filtres

How to move a marker on a figure?

9 vues (au cours des 30 derniers jours)
Dru
Dru le 12 Avr 2023
Commenté : Dru le 12 Avr 2023
I am trying to make an animation that moves a marker in a circle. I'm having trouble with moving the marker. This is my setup statement
markerhandle = plot(xdata, ydata, 'k.', 'MarkerSize', 36);
This is my statement to move the marker
markerhandle.set('xdata', 'ydata', ...
'Marker', 'k.', ...
'MarkerFaceColor', 'r', ...
'MarkerEdgeColor', 'r', ...
'MarkerSize', 36);
The second statement returns errors, however, I can make it kinda work by doing markerhandle = plot(ect...). This leaves all of the old markers in the figure and I only want one marker.
  2 commentaires
Dru
Dru le 12 Avr 2023
Modifié(e) : Dru le 12 Avr 2023
With this line of code
markerhandle.set(xdata, ydata, ...
'Marker', '.', ...
'MarkerFaceColor', 'k', ...
'MarkerEdgeColor', 'k', ...
'MarkerSize', 36);
I recieved this error
Error using matlab.graphics.chart.primitive.Line/set
Invalid parameter/value pair arguments.
Error in ActiveAnimation (line 51)
markerhandle.set(xdata, ydata, ...
Dru
Dru le 12 Avr 2023
Updated code that works as expected
markerhandle.set('Xdata', xdata, 'Ydata', ydata, ...
'Marker', '.', ...
'MarkerFaceColor', 'k', ...
'MarkerEdgeColor', 'k', ...
'MarkerSize', 36);

Connectez-vous pour commenter.

Réponse acceptée

Daniel
Daniel le 12 Avr 2023
There appear to be two problems:
  1. 'XData' and 'YData' have to be followed by the actual xdata and ydata for the new point.
  2. Since you specify the marker color separately in this syntax, the 'Marker' value should be '.' rather than 'k.'.
By the way, if you type 'doc markerhandle.set' into the command window after markerhandle is created, it pulls up the line properties, which will help you sort through how each name/value pair should be defined.
  1 commentaire
Dru
Dru le 12 Avr 2023
If xdata and ydata are my variable names do I just remove the quotation marks?

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by