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:
Reshape in Row First

Subject: Reshape in Row First

From: weihua xiong

Date: 19 Mar, 2006 12:55:50

Message: 1 of 8

Hi:

As we know, if I have vector
A = [ 1 2 3 4
     5 6 7 8];
if I use B = reshape(A,[1 8]);
the result is B = [1 5 2 6 3 7 4 8]
How can I get the result
B = [1 2 3 4 5 6 7 8] from matlab

Thanks

Subject: Reshape in Row First

From: us

Date: 19 Mar, 2006 13:02:27

Message: 2 of 8

weihua xiong:
<SNIP small <reshape> problem...

one of the solutions

     m=[1,2,3,4
        5,6,7,8]
     mr=reshape(m.',1,[])

us

Subject: Reshape in Row First

From: Chris

Date: 4 Aug, 2009 15:51:02

Message: 3 of 8

us <us@neurol.unizh.ch> wrote in message <ef2cda9.0@webx.raydaftYaTP>...
> weihua xiong:
> <SNIP small <reshape> problem...
>
> one of the solutions
>
> m=[1,2,3,4
> 5,6,7,8]
> mr=reshape(m.',1,[])
>
> us

Hi there I was wondering is there any way of reshaping row by row when you have more than one row, for example i have data:

'512' '487' '761' '503' '513' '484' '762' '495' '514' '481'.... in a 1x185 array and I want it to go

512 487 761 503
513 484 762 495
514 481 ... in a 4x45number of rows

but i can only get

512 495 761 483
487 512 491 765
761 484 515 495
503 765 482 513
513 478 764 484 in a 4x45
484
762
495
514
481

any help would be amazing

many thanks Chris

Subject: Reshape in Row First

From: Nathan

Date: 4 Aug, 2009 15:58:48

Message: 4 of 8

On Aug 4, 8:51 am, "Chris " <scu0...@reading.ac.uk> wrote:
> us <u...@neurol.unizh.ch> wrote in message <ef2cda...@webx.raydaftYaTP>...
> > weihua xiong:
> > <SNIP small <reshape> problem...
>
> > one of the solutions
>
> >      m=[1,2,3,4
> >         5,6,7,8]
> >      mr=reshape(m.',1,[])
>
> > us
>
> Hi there I was wondering is there any way of reshaping row by row when you have more than one row, for example i have data:
>
> '512'   '487'   '761'   '503' '513'     '484'   '762'   '495' '514'     '481'.... in a 1x185 array and I want it to go
>
> 512 487 761 503
> 513 484 762 495
> 514 481 ...  in a 4x45number of rows
>
> but i can only get
>
> 512     495     761     483
> 487     512     491     765
> 761     484     515     495
> 503     765     482     513
> 513     478     764     484  in a 4x45
> 484
> 762
> 495
> 514
> 481
>
> any help would be amazing
>
> many thanks Chris


A = [512 487 761 503 513 484 762 496];
B = reshape(A,4,[])';
%%%%%%%%%%%%%%%%%%%%%
B =
   512 487 761 503
   513 484 762 496

-Nathan

Subject: Reshape in Row First

From: Chris

Date: 5 Aug, 2009 08:51:01

Message: 5 of 8

Nathan <ngreco32@gmail.com> wrote in message <4c2a45aa-4e2d-4d62-bb48-3d174470e367@m3g2000pri.googlegroups.com>...
> On Aug 4, 8:51?am, "Chris " <scu0...@reading.ac.uk> wrote:
> > us <u...@neurol.unizh.ch> wrote in message <ef2cda...@webx.raydaftYaTP>...
> > > weihua xiong:
> > > <SNIP small <reshape> problem...
> >
> > > one of the solutions
> >
> > > ? ? ?m=[1,2,3,4
> > > ? ? ? ? 5,6,7,8]
> > > ? ? ?mr=reshape(m.',1,[])
> >
> > > us
> >
> > Hi there I was wondering is there any way of reshaping row by row when you have more than one row, for example i have data:
> >
> > '512' ? '487' ? '761' ? '503' '513' ? ? '484' ? '762' ? '495' '514' ? ? '481'.... in a 1x185 array and I want it to go
> >
> > 512 487 761 503
> > 513 484 762 495
> > 514 481 ... ?in a 4x45number of rows
> >
> > but i can only get
> >
> > 512 ? ? 495 ? ? 761 ? ? 483
> > 487 ? ? 512 ? ? 491 ? ? 765
> > 761 ? ? 484 ? ? 515 ? ? 495
> > 503 ? ? 765 ? ? 482 ? ? 513
> > 513 ? ? 478 ? ? 764 ? ? 484 ?in a 4x45
> > 484
> > 762
> > 495
> > 514
> > 481
> >
> > any help would be amazing
> >
> > many thanks Chris
>
>
> A = [512 487 761 503 513 484 762 496];
> B = reshape(A,4,[])';
> %%%%%%%%%%%%%%%%%%%%%
> B =
> 512 487 761 503
> 513 484 762 496
>
> -Nathan

Hi Nathan,

That work great thank you very much.

Kind regards
Chris Weeks

Subject: Reshape in Row First

From: Miltan Chowdhury

Date: 7 Mar, 2014 03:38:09

Message: 6 of 8

"us" wrote in message <ef2cda9.0@webx.raydaftYaTP>...
> weihua xiong:
> <SNIP small <reshape> problem...
>
> one of the solutions
>
> m=[1,2,3,4
> 5,6,7,8]
> mr=reshape(m.',1,[])
>
> us
use this function code
function y=reshapee(a,b,c)%%matrix reshape row wise
y=zeros(b,c);
for i=1:b
    for j=1:c
        y(i,j)=a(((i-1)*c)+j)
    end
end

    
        


    
    

Subject: Reshape in Row First

From: Miltan Chowdhury

Date: 7 Mar, 2014 03:42:08

Message: 7 of 8


> use this function code to reshape matrix in row wise
> function y=reshapee(a,b,c)%%matrix reshape row wise
> y=zeros(b,c);
> for i=1:b
> for j=1:c
> y(i,j)=a(((i-1)*c)+j)
> end
> end
>
>
>
>
>
>
>

Subject: Reshape in Row First

From: Miltan Chowdhury

Date: 7 Mar, 2014 03:43:08

Message: 8 of 8

"Miltan Chowdhury" wrote in message <lfbev1$b74$1@newscl01ah.mathworks.com>...
> "us" wrote in message <ef2cda9.0@webx.raydaftYaTP>...
> > weihua xiong:
> > <SNIP small <reshape> problem...
> >
> > one of the solutions
> >
> > m=[1,2,3,4
> > 5,6,7,8]
> > mr=reshape(m.',1,[])
> >
> > us
> use this function code
> function y=reshapee(a,b,c)%%matrix reshape row wise
> y=zeros(b,c);
> for i=1:b
> for j=1:c
> y(i,j)=a(((i-1)*c)+j)
> end
> end
>
>
>
>
>
>
>

Tags for 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