Change values input dialog inputdlg defaults mid-script running

4 views (last 30 days)
Hi,
I've got an input dialog box for code, which works perfectly for input to script. What I'm looking to try is to have the code change the default values to the last values input, provided MatLab isn't closed. Code below:
Default = {num2str(632.8),num2str(100),num2str(100),num2str(3),num2str(256),num2str(1)};
Prompt = {'Wavelength (nm)','Focal length (mm)','% radius','Channel (R,G or B)','Max value (<256)','Type (1-4)'};
Title = 'FZP Generator User Input Parameters';
Answer = inputdlg(Prompt, Title, 1, Default);
So once the script is ran for the first time, and say the focal length is changed from 100 to 200, the next time the script is ran I'd like the displayed input (default) to read 200 so I don't have to change each time as this is likely to be similar for a setup. Then when MatLab is closed and reopened, the script defaults return to those set in the script (as above).
(I guess it's defining a [6x1] but how to overlook the absence of this the first time the script is run and then read from it when it exists?)

Accepted Answer

Pete
Pete on 18 Nov 2014
Answer solved by saving all variables (save function) at end of script, then loading (load function) at start. I also include the exist function as a test at the very start which looks for any saved file. If this is there, the used values are loaded, if not the default values are used. A rather useful input technique for dialog boxes.

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!