Changing default values for inputdlg()

36 ビュー (過去 30 日間)
Michael
Michael 2014 年 3 月 10 日
編集済み: Michael 2014 年 3 月 13 日
I'm trying to work out a way such that if a user inputs some values into a dialogue box then exits it, those previous values are saved and then reused as the default values when the user open it again.
I've tried using the command in a loop with variables for the default answers which I then change i.e with m = answer(1). But when I try using variables instead on actual numbers like {'1', '2', '3'}, I get an error saying 'Default Answer must be a cell array of strings.'
Does anyone know how this may be done?

採用された回答

Mischa Kim
Mischa Kim 2014 年 3 月 10 日
編集済み: Mischa Kim 2014 年 3 月 10 日
Michael, does this do what you need?
defaultanswer = {'20','hsv'};
for ii = 1:2
prompt ={'Enter the matrix size for x^2:',...
'Enter the colormap name:'};
name = 'Input for Peaks function';
numlines = 1;
defaultanswer = inputdlg(prompt,name,numlines,defaultanswer);
end
I suspect that your variables are numeric, in which case you need to convert to string, using, e.g., the num2str command.
  3 件のコメント
Mischa Kim
Mischa Kim 2014 年 3 月 10 日
編集済み: Mischa Kim 2014 年 3 月 10 日
I just used the loop to open the dialog twice to show how to store answers from the dialog box for later use. Of course, you can also call inputdlg again and again in different parts of your code.
Michael
Michael 2014 年 3 月 13 日
編集済み: Michael 2014 年 3 月 13 日
Still having a bit of trouble with this,
I've written this out:
def = {'0.6','16','16','2','0.6','0.7','0.1','4'};
prompt ={'Mass', 'Spring 1', 'Spring 2', 'Damping Coefficent', 'Distance', 'Initial Displacement', 'Time Step', 'Total Time'};
dlg_title = 'Parameters';
numlines = 1;
options.Resize='on';
answer = inputdlg(prompt,dlg_title,numlines,def,options);
def = answer;
disp(def)
When the dialogue box open, the default values I specify at the begining are present, and when I change the values, and exit the box, disp(def) shows the default answers have been changed to the new values I put in. However when I open the box back up, the default values reset to what they were originally.
I've been having a lot of trouble with 'the variable might be used before it is defined' as i cant simply set the default answer at the begining to the final answer at the end before said answer is put in.
Do you have any other ideas?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInstall Products についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by