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 Kommentare

KL
KL am 21 Okt. 2017
How and when does BatchAbf.x get nIn elements?
Calvin Hobbes
Calvin Hobbes am 21 Okt. 2017
Bearbeitet: Calvin Hobbes am 21 Okt. 2017
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

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Jan
Jan am 21 Okt. 2017

0 Stimmen

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 Kommentare

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!
Jan
Jan am 21 Okt. 2017
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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Calvin Hobbes
Calvin Hobbes am 21 Okt. 2017
Bearbeitet: Calvin Hobbes am 21 Okt. 2017

0 Stimmen

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);

Kategorien

Mehr zu Geographic Plots finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by