Thread Subject: split arrays

Subject: split arrays

From: Juliette Salexa

Date: 8 Aug, 2009 21:47:01

Message: 1 of 4

a=[1 2 3];

If I now want: a1=[1 0 0], a2=[0 1 0 ], a3= [0 0 1]

Is there an internal matlab function to do this ?? rather than doing somehting like:

a1=[a(1) 0 0 ]; a2=[0 a(2) 0]; a3=[0 0 a(3)];

??

Does this:
http://www.mathworks.com/matlabcentral/fileexchange/24255

have this feature ??

Subject: split arrays

From: Matt Fig

Date: 8 Aug, 2009 23:25:18

Message: 2 of 4

"Juliette Salexa" <juliette.physicist@gmail.com> wrote in message <h5krol$r10$1@fred.mathworks.com>...
> a=[1 2 3];
>
> If I now want: a1=[1 0 0], a2=[0 1 0 ], a3= [0 0 1]
>
> Is there an internal matlab function to do this ?? rather than doing somehting like:
>
> a1=[a(1) 0 0 ]; a2=[0 a(2) 0]; a3=[0 0 a(3)];
>
> ??
>
> Does this:
> http://www.mathworks.com/matlabcentral/fileexchange/24255
>


Juliette,

Look at the example you gave. It does not line up with what you say you want. I.e.,

a2=[0 a(2) 0] = [0 2 0], NOT [0 1 0]

Subject: split arrays

From: Bruno Luong

Date: 8 Aug, 2009 23:32:02

Message: 3 of 4

"Juliette Salexa" <juliette.physicist@gmail.com> wrote in message <h5krol$r10$1@fred.mathworks.com>...
> a=[1 2 3];
>
> If I now want: a1=[1 0 0], a2=[0 1 0 ], a3= [0 0 1]
>
> Is there an internal matlab function to do this ?? rather than doing somehting like:
>
> a1=[a(1) 0 0 ]; a2=[0 a(2) 0]; a3=[0 0 a(3)];
>
> ??
>
> Does this:
> http://www.mathworks.com/matlabcentral/fileexchange/24255
>
> have this feature ??

No. Rather

c=num2cell(diag(a),2)

Bruno

Subject: split arrays

From: Juliette Salexa

Date: 9 Aug, 2009 00:56:01

Message: 4 of 4

Thanks Matt,
That was a clumsy typo on my part, I meant that I wanted [0 2 0] and [ 0 0 3]

Thanks Bruno,
That works perfectly

Much appreciated!

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
split array Sprinceana 9 Aug, 2009 04:26:36
rssFeed for this Thread

Contact us at files@mathworks.com