Clear Filters
Clear Filters

How to move a marker on a figure?

9 views (last 30 days)
Dru
Dru on 12 Apr 2023
Commented: Dru on 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 Comments
Dru
Dru on 12 Apr 2023
Edited: Dru on 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 on 12 Apr 2023
Updated code that works as expected
markerhandle.set('Xdata', xdata, 'Ydata', ydata, ...
'Marker', '.', ...
'MarkerFaceColor', 'k', ...
'MarkerEdgeColor', 'k', ...
'MarkerSize', 36);

Sign in to comment.

Accepted Answer

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

Sign in to comment.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!