From: Luca Cerone on
Hi everybody,
I'm sorry if the question is silly,
but I couldn't find in the help nor in the newsgroup.

I've a vector v and have to assign its values to different variables,
something like:

a=v(1);
b=v(2);
c=v(3);
..
..
..
and so on.

Is there any easy way to write such a piece of code?
Thanks a lot in advance to you all.
Cheers, -Luca
From: Matt Fig on
Would you mind explaining why you would want to do such a thing? Usually the reason for doing something like this won't justify the further trouble you will get later on in the code.
From: Faraz Afzal on
"Luca Cerone" <luca_cerone#_remove_this#@yahoo.it> wrote in message <i0suvg$eou$1(a)fred.mathworks.com>...
> Hi everybody,
> I'm sorry if the question is silly,
> but I couldn't find in the help nor in the newsgroup.
>
> I've a vector v and have to assign its values to different variables,
> something like:
>
> a=v(1);
> b=v(2);
> c=v(3);
> .
> .
> .
> and so on.
>
> Is there any easy way to write such a piece of code?
> Thanks a lot in advance to you all.
> Cheers, -Luca

Hi Luca,

I wonder your use of this thing..

Hint..

Go for Doc char
Then look for ASCII characters from 97.,...122
May it helps
Regards
Faraz
From: us on
"Luca Cerone" <luca_cerone#_remove_this#@yahoo.it> wrote in message <i0suvg$eou$1(a)fred.mathworks.com>...
> Hi everybody,
> I'm sorry if the question is silly,
> but I couldn't find in the help nor in the newsgroup.
>
> I've a vector v and have to assign its values to different variables,
> something like:
>
> a=v(1);
> b=v(2);
> c=v(3);
> .
> .
> .
> and so on.
>
> Is there any easy way to write such a piece of code?
> Thanks a lot in advance to you all.
> Cheers, -Luca

well... since you're a seasoned ML/CSSM user, let's assume you have very good reason for doing this...

one of the solutions

v=1:3;
v=num2cell(v);
[a,b,c]=deal(v{:})
% a = 1
% b = 2
% c = 3

us
From: Jan Simon on
Dear Luca,

> us wrote:
> well... since you're a seasoned ML/CSSM user, let's assume you have very good reason for doing this...
> v=1:3;
> v=num2cell(v);
> [a,b,c]=deal(v{:})

But for less experienced Matlab users: Prefer other solutions, e.g.:
- Stay at the vector, vectors are nice.
- Dynamic field names:
for k = 1:numel(v)
data.(char(96 + k)) = v(k);
end

Jan