Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Convert 2d matrix into several 1 D array

Subject: Convert 2d matrix into several 1 D array

From: Amith

Date: 24 Dec, 2012 18:55:12

Message: 1 of 5

Can anyone please help me with the following :

a=[1 2 3; 4 5 6; 7 8 9]

i want to change it into
b1=[1 2 3]
b2=[4 5 6]
b3=[7 8 9]

i have tried using a for loop
j=0;
for i=1:1:3
bi(j+1,:)=a(((3*j)+1):((3*j)+3))
j=j+1;
end

The issue is i am not having b1, b2 and b3 (seperate arrays) but only 1 b3.

i want matlab to understand that i need 3 seperate arrays .

regards

amith

Subject: Convert 2d matrix into several 1 D array

From: dpb

Date: 24 Dec, 2012 20:39:00

Message: 2 of 5

On 12/24/2012 12:55 PM, Amith wrote:
> Can anyone please help me with the following :
>
> a=[1 2 3; 4 5 6; 7 8 9]
>
> i want to change it into b1=[1 2 3]
> b2=[4 5 6]
> b3=[7 8 9]
>
...

>
> The issue is i am not having b1, b2 and b3 (seperate arrays) but only 1 b3.
>
> i want matlab to understand that i need 3 seperate arrays .
...

Generally that is a bad idea. For background on why and ways to
accomplish the same thing w/o 'poofing' variables into the ML workspace
search for 'Alternatives to the eval function' in the documentation.

--

Subject: Convert 2d matrix into several 1 D array

From: Amith

Date: 24 Dec, 2012 21:14:12

Message: 3 of 5

dpb <none@non.net> wrote in message <kbaeg3$p1j$1@speranza.aioe.org>...
> On 12/24/2012 12:55 PM, Amith wrote:
> > Can anyone please help me with the following :
> >
> > a=[1 2 3; 4 5 6; 7 8 9]
> >
> > i want to change it into b1=[1 2 3]
> > b2=[4 5 6]
> > b3=[7 8 9]
> >
> ...
>
> >
> > The issue is i am not having b1, b2 and b3 (seperate arrays) but only 1 b3.
> >
> > i want matlab to understand that i need 3 seperate arrays .
> ...
>
> Generally that is a bad idea. For background on why and ways to
> accomplish the same thing w/o 'poofing' variables into the ML workspace
> search for 'Alternatives to the eval function' in the documentation.
>
> --
> for k=1:3
a_k=k;
end

is the above expression proper for having an output as follows:
a_1=1
a_2=2
a_3=3

i tried it in the matlab but dont get the expect output.

Can you suggest on how this could be achieved

Subject: Convert 2d matrix into several 1 D array

From: dpb

Date: 25 Dec, 2012 00:07:54

Message: 4 of 5

On 12/24/2012 3:14 PM, Amith wrote:
...

> i tried it in the matlab but dont get the expect output.
>
> Can you suggest on how this could be achieved

See previous answer -- this is _NOT_ the way to do whatever it is you
want to do in Matlab.

Did you follow the advice on finding the section in the documentation
that discusses why and how to process your data w/o doing so (or in last
resort, if you are insistent on going down the wrong path, it even has
that too).

--

Subject: Convert 2d matrix into several 1 D array

From: Steven_Lord

Date: 31 Dec, 2012 05:11:54

Message: 5 of 5



"Amith " <amithkhandakar@hotmail.com> wrote in message
news:kba8eg$koi$1@newscl01ah.mathworks.com...
> Can anyone please help me with the following :
>
> a=[1 2 3; 4 5 6; 7 8 9]
>
> i want to change it into b1=[1 2 3]
> b2=[4 5 6]
> b3=[7 8 9]

See question 6 in the Programming section of the newsgroup FAQ for an
explanation why this is a Bad Idea and the alternatives you should use
instead.

http://matlab.wikia.com/wiki/FAQ

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Tags for this Thread

No tags are associated with this thread.

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.

Contact us