Hello
I am using the following code to iteratively pan along the x-axis in small steps and it works fine.
asig = csvread('tek0001CH1.csv',15,0);
%tim =sig(1:1000000,1);
aamp = asig(1:2000000,2);
ts = asig(2,1) - asig(1,1);
tim = [0:2000000 - 1]*ts;
time = tim';
plot(time, aamp);
%set(h,'Motion','horizontal','Enable','on');
axis([0 max(tim) -0.1 1.9]);
ax_handle = gca;
xlimit_orig = get(ax_handle, 'Xlim');
win_xlimit = [0 0.001];
offset = 0.001;
% %Iterativley change the xlimit for the axes to pan across the figure
while win_xlimit(2) <= xlimit_orig(2)
set(ax_handle, 'Xlim', win_xlimit);
pause(0.05);
win_xlimit = win_xlimit + offset;
end
However, if I want to stop in the middle of panning (If I see something of interest in the plot), how do I do it? I tried using waitforbuttonpress fcn and that doesn't work very well. Any suggestions please.
Thanks

 채택된 답변

Jan
Jan 2011년 8월 18일

1 개 추천

You can use a toggle button:
buttonH = uicontrol('Sytle', 'ToggleButton', ...
'Units', 'pixels', ...
'Position', [5, 5, 60, 20], ...
'String', 'Pan', ...
'Value', 1);
while win_xlimit(2) <= xlimit_orig(2)
set(ax_handle, 'Xlim', win_xlimit);
pause(0.05);
if get(buttonH, 'Value') == 1
win_xlimit = win_xlimit + offset;
end
end

댓글 수: 6

vsee
vsee 2011년 8월 18일
Thanks. I tried this. I just added
handle = uicontrol;
in my code and it added a push button in my plot. How can I make this interactive? Is there a property called pan for uicontrol
Jan
Jan 2011년 8월 18일
No, there is no 'pan' property. My example uses an interaction already. Therefore I do not understand your question.
Fangjun Jiang
Fangjun Jiang 2011년 8월 18일
Here is how it works out!
%%
ts=0.5;
tim = (0:2000000)*ts;
aamp=sin(tim);
h=figure(1);
plot(tim, aamp);
%set(h,'Motion','horizontal','Enable','on');
axis([0 max(tim) -1 1]);
buttonH = uicontrol('parent',h,...
'style', 'togglebutton', ...
'Units', 'pixels', ...
'Position', [5, 5, 60, 20], ...
'String', 'Pan', ...
'Value', 1);
ax_handle = gca;
xlimit_orig = get(ax_handle, 'Xlim');
win_xlimit = [0 10];
offset = 10;
% %Iterativley change the xlimit for the axes to pan across the figure
while win_xlimit(2) <= xlimit_orig(2)
set(ax_handle, 'Xlim', win_xlimit);
pause(0.05);
if get(buttonH, 'Value') == 1
win_xlimit = win_xlimit + offset;
end
end
vsee
vsee 2011년 8월 18일
Thanks much Fangjun and Jan. The panning works and am able to stop it by pressing the toggle button on the plot and can also add data cursors to the plot when paused. However, I can't zoom in or zoom out when paused. Is this something that I am going to have to live with?
Fangjun Jiang
Fangjun Jiang 2011년 8월 18일
Yes, you can. But need to move the set(ax_handle,...) line into the if statement. like below.
while win_xlimit(2) <= xlimit_orig(2)
pause(0.05);
if get(buttonH, 'Value') == 1
win_xlimit = win_xlimit + offset;
set(ax_handle, 'Xlim', win_xlimit);
end
end
vsee
vsee 2011년 8월 18일
Thanks again. That worked. Appreciate it.

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

추가 답변 (1개)

Fangjun Jiang
Fangjun Jiang 2011년 8월 16일

1 개 추천

Nice work! I recommend you making a generic function which includes mostly the code in your while-loop. This generic function can take some arguments and pan any axes in a figure. When you want to stop, just press Ctrl+C to stop the execution of the function. When you want to continue, you just run the function again.
Layout a list of the input arguments,such as the figure handle, axes handle, how fast you want it move, the initial xlimit, etc. I think it can be done.

댓글 수: 1

vsee
vsee 2011년 8월 18일
Even if I had a function, how do I dynamically change the variable's value that I read from the keyboard, so that when the value changes, the plot begins to pan again.

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

카테고리

도움말 센터File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

제품

태그

아직 태그를 입력하지 않았습니다.

질문:

2011년 8월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by