Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

how to convert vector to a matrix having 3 colums and n rows

Status
Not open for further replies.

moonnightingale

Full Member level 6
Joined
Sep 17, 2009
Messages
362
Helped
5
Reputation
10
Reaction score
5
Trophy points
1,298
Activity points
3,832
am having larger data vector. I want to convert it to a matrix having 3 colums.

Example is here

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

I Want to have my output like this

n= 1 2 3
4 5 6
7 8 9

I tried reshape for this as well but it gave output like this

n= 1 4 7
2 5 8
3 6 9
which is not required by me.plz help me
 

Re: how to convert vector to a matrix having 3 colums and n

If I am not missing anything, this is pretty simple. Simply read the first 3 elements into frist vector, then next 3 into 2nd and so on.

m= [ 1 2 3 4 5 6 7 8 9]
m3 = [ [1 2 3] [4 5 6] [7 8 9]]
 

Re: how to convert vector to a matrix having 3 colums and n

I told I am having larger data vector. I want to convert it to a matrix having 3 colums.

my data is like this

[ 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 ..........................................................till 5000]

i want to have this in columns of three as illustrated above
Thanks
 

Re: how to convert vector to a matrix having 3 colums and n

moonnightingale said:
I told I am having larger data vector. I want to convert it to a matrix having 3 colums.

my data is like this

x = [ 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 ..........................................................till 5000]

i want to have this in columns of three as illustrated above
Thanks


reshape(x,length(x)/3,3)

Make sure that x is divisible by 3 otherwise zero pad it
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top