Turn one matrix into many matrices

Say I have an Nx2 Matrix, called 'A' -- how would I turn this into N vectors called 'A1', 'A2'...'AN'?
My current solution is to open Excel, add row headers, and then import the data. Looking for a more automated way to do this in MATLAB.
More details:
I have two matrices, one is Nx2, the other is MxP.
For each row in matrix 1, I need to extract rows out of matrix 2 and append four columns of additional data to them. Sometimes a particular row could be extracted from the second matrix multiple times. In that case, the appended data would be different each time.
At the end of the day, I need N matrices of size Qx(P+4). I would prefer this to having one 3D matrix of size NxQx(P+4), as the number of rows that I extract from the second matrix will not be the same each time.
Since I would prefer to have N matrices as the output, I thought it would be best to just start with N vectors as the input.

 Akzeptierte Antwort

Sean de Wolski
Sean de Wolski am 4 Apr. 2011

1 Stimme

DON'T DO THIS!
Explain the problem to us and we can help you find a better way.

7 Kommentare

Chris
Chris am 4 Apr. 2011
Hmmm, ok. I am definitely open minded that there can be a better way, so I will try to explain. Give me a couple minutes to write it up and post as the next comment :)
Chris
Chris am 4 Apr. 2011
I have two matrices, one is Nx2, the other is MxP.
For each row in matrix 1, I need to extract rows out of matrix 2 and append four columns of additional data to them. Sometimes a particular row could be extracted from the second matrix multiple times. In that case, the appended data would be different each time.
At the end of the day, I need N matrices of size Qx(P+4) (or, yes, one 3D matrix, NxQx(P+4)).
Sean de Wolski
Sean de Wolski am 4 Apr. 2011
Can you provide a small example (input/operation/output) please. Edit your original question so that you can use the markup which makes it easier for us to read.
Chris
Chris am 4 Apr. 2011
Actually, I should be more clear, each time I extract rows from the second matrix, it will typically be a different amount.
So at the end of the day, having N differently named Qx(P+4) matrices is preferable to having a single 3D matrix, which might need a bunch of zeros to fill in extra space since Q is different depending on how many rows I extract from the second matrix.
Since I would prefer to have N matrices as the output, I thought it would be best to just start with N vectors as the input.
Sean de Wolski
Sean de Wolski am 4 Apr. 2011
This is what cell arrays are for.
Chris
Chris am 4 Apr. 2011
Ah, yes, I see now. Thank you!
Jan
Jan am 4 Apr. 2011
@Sean: Exactly. A CELL array is an efficient and clean solution. It is impressive, that the OP and the wiki artical use the same "A1, A2, ..." naming scheme. +1

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by