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

1 次查看(过去 30 天)
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');

请先登录,再进行评论。

更多回答(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