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!