Seeing the image overlaid on image
2 views (last 30 days)
Show older comments
I have this code with an image, and a diagonal line and a point plotted on the image. I want the point to move straight up and down whenever I press the space bar. When I run this code, I get two separate things - one with the image, line and dot, and one with the dot that moves up and down but on a blank background. What do I need to do to combine the two?
fs=100e3; % sampling frequency (Hz)
f=5000; % stimulus frequency (Hz)
dur = .0002; % duration (s)
ns = dur*fs; % # samples
t=(0:1:ns-1)/fs; % time vector (s)
a=1; % amplitude (arbitrary)xcsdg
phi=0; %phase (radians)
x=0; % x-position (fixed)
imshow('AvgBscan.tiff');
[rows, columns, numberOfColorChannels] = size('AvgBscan.tiff');
x = [0,150];
y = [0,100];
line(x,y, 'LineWidth', 4, 'Color', [1, 0, 1]);
plot(50,33,'yo', 'MarkerSize', 12)
for t_i = 1:length(t) % for each point in time
y = a*sin(2*pi*f*t(t_i) + phi); % calculate y-position of circle according to the output of a sine wave at that time
axis on
hold on;
h=figure;
plot([-1 1],[0 0],'k--');
xlim([-1 1]);
ylim([-1 1]);
pause; %close all;
end
Answers (1)
Madhav Thakker
on 9 Sep 2020
Hi,
You can use hold on for this purpose. You can change the pointer by changing the YData of the plot. I am attaching a code snippet for better understanding.
x = [-10,150];
y = [-10,150];
line(x,y, 'LineWidth', 4, 'Color', [1, 0, 1]);
hold on
pl = plot(0,0,'yo', 'MarkerSize', 12)
axis on
hold on
for t_i = 1:length(t) % for each point in time
y = a*sin(2*pi*f*t(t_i) + phi) % calculate y-position of circle according to the output of a sine wave at that time
hold on;
axis on;
pl.YData = y;
hold on
plot([-1 1],[0 0],'k--');
xlim([-1 1]);
ylim([-1 1]);
pause; %close all;
end
Hope this helps.
0 Comments
See Also
Categories
Find more on Line Plots 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!