필터 지우기
필터 지우기

Make an asterisk or point move sinusoidally

조회 수: 1 (최근 30일)
SS
SS 2020년 8월 1일
댓글: Cris LaPierre 2020년 8월 1일
Hi, I plotted an asterisk on the image mentioned in the code below. I am supposed to get the asterisk to move in a sinusoidal motion directly on the image. However, with my code, I am getting the asterisk on the image seperately and then a plot of a sine wave separately. How do I combine the two?
  댓글 수: 1
Cris LaPierre
Cris LaPierre 2020년 8월 1일
Please copy and paste your code rather than sharing a screenshot of it.

댓글을 달려면 로그인하십시오.

답변 (1개)

Cris LaPierre
Cris LaPierre 2020년 8월 1일
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
SS
SS 2020년 8월 1일
I did what you suggested and it all worked! However because the image and the plot are overlayed, there is some strange flickering going on when I run it. Do I use a double buffer for this issue
Cris LaPierre
Cris LaPierre 2020년 8월 1일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by