Seeing the image overlaid on image
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
2 comentarios
Respuestas (1)
Madhav Thakker
el 9 de Sept. de 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 comentarios
Ver también
Categorías
Más información sobre Line Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!