Azzera filtri
Azzera filtri

How to move a marker on a figure?

9 visualizzazioni (ultimi 30 giorni)
Dru
Dru il 12 Apr 2023
Commentato: Dru il 12 Apr 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 Commenti
Dru
Dru il 12 Apr 2023
Modificato: Dru il 12 Apr 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 il 12 Apr 2023
Updated code that works as expected
markerhandle.set('Xdata', xdata, 'Ydata', ydata, ...
'Marker', '.', ...
'MarkerFaceColor', 'k', ...
'MarkerEdgeColor', 'k', ...
'MarkerSize', 36);

Accedi per commentare.

Risposta accettata

Daniel
Daniel il 12 Apr 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 Commento
Dru
Dru il 12 Apr 2023
If xdata and ydata are my variable names do I just remove the quotation marks?

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange

Prodotti


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by