Seeing the image overlaid on image

2 ビュー (過去 30 日間)
SS
SS 2020 年 9 月 4 日
回答済み: Madhav Thakker 2020 年 9 月 9 日
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 件のコメント
KSSV
KSSV 2020 年 9 月 4 日
Read about hold on, set.
SS
SS 2020 年 9 月 4 日
Hi, I did that and changed some things but still no luck. Would appreciate if you could assist further.
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)
phi=0; %phase (radians)
x=50; % x-position (fixed)
h = plot(50,33,'yo', 'MarkerSize', 12)'
for t_i = 1:length(t) % for each point in time
imshow('AvgBscan.tiff');
axis on;
hold on;
y = a*sin(2*pi*f*t(t_i) + phi)
% plot circle at x vs. y
set(h, 'YData', Y);
drawnow
plot([-1 1],[0 0],'k--');
xlim([0 100]);
ylim([0 80]);
pause; %close all;
end

サインインしてコメントする。

回答 (1 件)

Madhav Thakker
Madhav Thakker 2020 年 9 月 9 日
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.

カテゴリ

Help Center および File ExchangeConvert Image Type についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by