Change values input dialog inputdlg defaults mid-script running

3 次查看(过去 30 天)
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?)

采纳的回答

Pete
Pete 2014-11-18
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by