Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
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?

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 8 Aug. 2015
save('D Variables.mat', answer, '-append')
  6 Kommentare
Ali Y.
Ali Y. am 10 Aug. 2015
Bearbeitet: Ali Y. am 10 Aug. 2015
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');

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by