Make an asterisk or point move sinusoidally
1 view (last 30 days)
Show older comments

1 Comment
Answers (1)
Cris LaPierre
on 1 Aug 2020
Your code is written to create 2 separate figures. The figure command explicitly tells MATLAB to create a new figure window rather than plotting into the current axes.
In order to combine your two figures onto the same axes, you will need to use the command hold on. Once completed, turn hold off.
Consider this example using an image included with MATLAB.
img = imread('peppers.png')
imshow(img)
hold on
h=plot(100,300,'w*');
hold off
Then, if I wanted to move the asterisk up and down, just change the YData property using the line object variable h:
h.YData = 100;
If I wanted to make it move sinusoidally, I could update the XData and YData properties inside a for loop. You might need to add a short pause in the loop so you can actually see the motion.
3 Comments
Cris LaPierre
on 1 Aug 2020
Not sure. I just tried it on my computer and it didn't flicker at all. If could be due to your graphics card, or it might be related to the size of your image. You might see if some suggestions in this post are helpful.
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!