Dear community, apologies for asking a simple and multiple-times-asked question...
[BatchAbf.x,~]=ginput(nIn);
% some lines are executed...
waitfor(numel(BatchAbf.x)=nIn);
% do not execute from here down until above condition is met
I know i can get away with pause and press enter, but this solution is more suited.
Any help greatly appreciated

댓글 수: 2

KL
KL 2017년 10월 21일
How and when does BatchAbf.x get nIn elements?
Calvin Hobbes
Calvin Hobbes 2017년 10월 21일
편집: Calvin Hobbes 2017년 10월 21일
BatchAbf.x gets the (index) output of ginput function. nIn is a number (1 or 2 or ...) that determines the number of inputs ginput demands.
In other words if nIn = 2. I click twice on a graph, BatchAbf.x will get two index values, and thusly numel(BatchAbf.x) = nIn

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

 채택된 답변

Jan
Jan 2017년 10월 21일

0 개 추천

But ginput(n) waits already until the user has pressed the key n times. Then
if nIn = 2. I click twice on a graph, BatchAbf.x will get two index values, and
numel(BatchAbf.x) = nIn
is solved by the posted code already:
[BatchAbf.x, ~] = ginput(nIn);
Then what exactly is the problem?

댓글 수: 2

True that! I need to explain it a lot better, and now i understand what KL meant by their question...
GUIDE generated SignalOverview contains plots and pushbuttons.
Upon pushbutton1 click, RejectPeak is called.
If the user clicks on (in this instance) object handles.axes2 then numInd function that contains the ginput is called. Problem is that the moment i press the pushbutton1 the code runs to do something with BatchAbf.x before ginput is even engaged...
function varargout = SignalOverview(varargin)
% ...
function pushbutton1_Callback(hObject, eventdata, handles)
RejectPeak
end
end
function RejectPeak
% .....
function varargout = numInd(varargin)
[BatchAbf.x,~]=ginput(nIn);
end
set(handles.axes2,'ButtonDownFcn', @numInd);
waitfor(numel(BatchAbf.x)=nIn);
% do something with BatchAbf.x
end
Thank you for your time!
I do not understand the purpose of the code. Do you mean:
function RejectPeak
...
[BatchAbf.x,~]=ginput(nIn);
% do something with BatchAbf.x
end
What is the reason for setting a ButtonDown function, which calls a nested function, when this function can be called directly?
Or perhaps you want:
function RejectPeak
set(handles.axes2,'ButtonDownFcn', @numInd);
end
function varargout = numInd(varargin)
[BatchAbf.x,~]=ginput(nIn);
% do something with BatchAbf.x
end

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

추가 답변 (2개)

Calvin Hobbes
Calvin Hobbes 2017년 10월 21일
편집: Calvin Hobbes 2017년 10월 21일

0 개 추천

Dear all, thank you all for your input. Problem solved. I was trying to do something very simple in a convoluted manner, while loop could also work elegantly, however i went for the simplest solution, taking advantage of indeed the fact the ginput waits for completion beore executing subsequent code. The real problem i was trying to overcome was to get the user to first click on the desired (one of many) plot in order to get the correct handle, and then initiate the rest...
set(handles.axes2,'ButtonDownFcn', 'BatchAbf.axH=1'); % not getting the handle but a value that is meaningful for indexing
set(handles.axes2,'ButtonDownFcn', 'BatchAbf.axH=2'); % not getting the handle but a value that is meaningful for indexing
while isempty(BatchAbf.axH)==1
waitforbuttonpress; % code waits for correct user click
end
[BatchAbf.x,~] = ginput(nIn);

카테고리

도움말 센터File Exchange에서 Geographic Plots에 대해 자세히 알아보기

질문:

2017년 10월 21일

편집:

2017년 10월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by