フィルターのクリア

Dynamic (non-string) variable name in Matlab 'save' function, using inputdlg

1 回表示 (過去 30 日間)
Ali Y.
Ali Y. 2015 年 8 月 8 日
コメント済み: Walter Roberson 2015 年 8 月 10 日
Hi everybody,
Is it possible to define the name of 'save' function's variable dynamically by using inpudlg. I want to save and append my derived variables to a workspace, table, or text file. So, at the end I have my derived variables.
prompt = {'Enter a name for the derived variable:'};
dlg_title = 'Input';
num_lines = 1;
defAns = {''};
answer = inputdlg(prompt,dlg_title,num_lines,defAns);
answer = devar; % answer and devar are going to change
save('D Variables.mat', 'answer', '-append')
In the last line of the above code, I want the 'answer', that is a string, to be changed as the result of inputdlg result, i.e. answer that is dynamic.
Though, combination of 'array2table' and 'writetable' functions let me to have my variable (with its header), I am not able to append the new variable to the previous storied variables.
How can I fix this code?

採用された回答

Walter Roberson
Walter Roberson 2015 年 8 月 8 日
save('D Variables.mat', answer, '-append')
  6 件のコメント
Ali Y.
Ali Y. 2015 年 8 月 10 日
編集済み: Ali Y. 2015 年 8 月 10 日
Thank you Walter, for your help. For those having my way of cognition, and expression, I would suggest having a look at the concept of 'dynamic structure name' and 'dynamic field name', in addition to the tips of Walters.
My code got functioning as
devar = ones(10,1);
prompt = {'Enter a name for the derived variable:'};
dlg_title = 'Input';
num_lines = 1;
defAns = {''};
answer = inputdlg(prompt,dlg_title,num_lines,defAns);
MYDATA(answer{1}) = devar;
save('DVariabels.mat', '-struct', 'MYDATA', '-append');
Walter Roberson
Walter Roberson 2015 年 8 月 10 日
You probably mean
MYDATA.(answer{1}) = devar;

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by