MATLAB: Assign rename of structure with input command

inputrenamestructures

Hello
I am trying to make some of my scripts a bit more easy to use.I am stuck on the rename option of a structure combined with the input command.
What i would like to have is
file=input('Enter the name .dat e.g. "fname.dat" = ')
S = input('Enter a name for the structure = ...')
A=load(file);
S.H1 = A(:,2);
S.H2 = A(:,3);
S.H3 =A(:,4);
Something like that i have but it does not work
how can i finally use the input command in a way that will prompt me and alter the name of the structure?
thank you

Best Answer

I also do not advocate the use of eval.
You could use "assignin", e.g.
S.H1 = A(:,2);
S.H2 = A(:,3);
S.H3 = A(:,4);
userName = 'ABC';
assignin ( 'base', userName, S ); this assuigns S to the variable name ABC
or put it in a sub function:
function AssignmentFunction ( S, userName )
assignin ( 'caller', userName, S )
end
However I cant really think why you want to do this - if you explain in a bit more detail what your end goal is (how are you using these renamed variables) you will get better help...
Related Question