Open user input in background

6 views (last 30 days)
Philipp Schumacher
Philipp Schumacher on 14 Oct 2020
Answered: Satwik on 28 Mar 2025
I have a question about the user input dialog. I want to do the following: I have some measuring points and want to get a function for them. Therefore, the cftool is openend so the user can choose manually which polynomial degree would fit best. In the following, an input dialog is opened, so the user can type in the polynominal degree. This is how it should work. The problem is, that the input dialog is in the line after cftool. So the input dialog is openend, but the user in not able to choose anything in the cftool. By minimizing it, it minimizes all Matlab windows.
I hope the problem is described clearly. Is it possible to open the user input in the background? Or can I use the waitfor() function? But how can I address the cftool?
cftool(x,y);
answer = inputdlg(...);

Answers (1)

Satwik
Satwik on 28 Mar 2025
I understand that the issue here is that the input dialog appears before the user has had a chance to interact with the 'cftool'.
To address this, the 'waitfor' function can be used to pause the execution of the script until the 'cftool' window is closed. Unfortunately, 'cftool' does not provide a direct handle to use with 'waitfor', but we can work around this by using a modal dialog box to pause execution until the user indicates they are done with the 'cftool'.
Here is a way to achieve the desired behavior using a simple message box as a blocking mechanism:
% Open the Curve Fitting Tool
cftool(x, y);
% Display a modal dialog box to wait for the user to finish with cftool
uiwait(msgbox('Close this dialog when you are done with cftool and have decided on the polynomial degree.', 'Info', 'modal'));
% After the user closes the dialog, open the input dialog
answer = inputdlg('Enter the polynomial degree:', 'Polynomial Degree', 1);
% Continue with the rest of your script using the user's input
if ~isempty(answer)
polyDegree = str2double(answer{1});
% Use the polynomial degree for further processing
disp(['User selected polynomial degree: ', num2str(polyDegree)]);
% Add your further processing code here
end
I hope this helps!

Categories

Find more on Curve Fitting Toolbox in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!