Store a double value into the cell array element

6 Ansichten (letzte 30 Tage)
Fuad Numan
Fuad Numan am 6 Apr. 2012
I have a cell array, e.g
name={'A','B','C'};
I would like to extract the name elements and use them as variables, we know that,
name{1}=A
I want to assign 'A' a double value or vector;
name{1}=[1 2 3]; % this one is definitely wrong, it is just for example
then when i call A from the command-window, it should show [1 2 3]; is it possible to do that?
appreciate ur help

Akzeptierte Antwort

Geoff
Geoff am 6 Apr. 2012
You'd need to use eval, but there's almost always a good reason not to do what you're trying to do.
  1 Kommentar
Fuad Numan
Fuad Numan am 6 Apr. 2012
Thanx Geoff
the eval function used after the variable declaration;
I mean the variable has not assigned any values yet,
what I want to do is to use the cell array in a for loop, e.g.
name={'A' 'B' 'C'};
for i=1:3
name{i}=50*i^2;
end
I tried your suggestion,
eval(name{1})=50;
but it seems the A variable should assign a value before the declaration of cell array name.
the loop i gonna use is to long, i want to make it shorter and faster and store the variables in mat file.
Thanks again

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Tables 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