How to move a marker on a figure?

9 次查看(过去 30 天)
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 个评论
Dru
Dru 2023-4-12
编辑:Dru 2023-4-12
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 2023-4-12
Updated code that works as expected
markerhandle.set('Xdata', xdata, 'Ydata', ydata, ...
'Marker', '.', ...
'MarkerFaceColor', 'k', ...
'MarkerEdgeColor', 'k', ...
'MarkerSize', 36);

请先登录,再进行评论。

采纳的回答

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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

标签

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by