http://www.mathworks.com/matlabcentral/newsreader/view_thread/306469
MATLAB Central Newsreader  2D array to 1D array
Feed for thread: 2D array to 1D array
enus
©19942015 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Tue, 19 Apr 2011 00:16:04 +0000
2D array to 1D array
http://www.mathworks.com/matlabcentral/newsreader/view_thread/306469#831836
Brianne
I have a matrix that is 9 x 52. Nine represents the maximum number of circumferential locations at a specificed longitudinal location around a model and 52 represents the longitudinal location along the model. For example, at longitudinal station #1 there are 4 circumferential values. At station #5 there are 8 circumferential values. However, MATLAB pads in zeros to make the matrix a square. <br>
<br>
My question is how to I grab those specific values out of the 2D array and place it into a 1D array? The reshape function will not work because the matrix dimension will be changing. <br>
<br>
For the purpose of my question I will use a simpler example. Assume A is a 6 x 6 matrix. For columns 1 through 4, I want to put the values of rows 1 through 4 into a 1D array. Then append column 5 and rows 1 through 5 to the 1D array. Then append column 6 and rows 1 through 6 to the 1D array. Finally the 1D array would look like B. <br>
<br>
A =[<br>
0 0 0 0 1 1<br>
0 0 0 0 1 1<br>
0 0 0 0 1 1<br>
0 0 0 0 1 1<br>
0 0 0 0 1 1<br>
0 0 0 0 0 1];<br>
<br>
B = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1];<br>
<br>
I would like this process to be automated because of the size of the matrix and the real matrix is not in any specific order. For example, columns 1 through 4 contain 4 of the necessary rows, but columsn 5, 6, 10 contain 8 of the necessary rows. I know how many rows I should take for each column. Also I can not use a sparse function to remove the padding because there are values that are zero and actually mean something. While other values are zeros and is just there for padding. <br>
<br>
Thank you in advanced.

Tue, 19 Apr 2011 03:26:04 +0000
Re: 2D array to 1D array
http://www.mathworks.com/matlabcentral/newsreader/view_thread/306469#831859
Roger Stafford
"Brianne " <brianne.y.williams@aero.org> wrote in message <ioik84$mnc$1@fred.mathworks.com>...<br>
> I have a matrix that is 9 x 52. Nine represents the maximum number of circumferential locations at a specificed longitudinal location around a model and 52 represents the longitudinal location along the model. For example, at longitudinal station #1 there are 4 circumferential values. At station #5 there are 8 circumferential values. However, MATLAB pads in zeros to make the matrix a square. <br>
> <br>
> My question is how to I grab those specific values out of the 2D array and place it into a 1D array? The reshape function will not work because the matrix dimension will be changing. <br>
> <br>
> For the purpose of my question I will use a simpler example. Assume A is a 6 x 6 matrix. For columns 1 through 4, I want to put the values of rows 1 through 4 into a 1D array. Then append column 5 and rows 1 through 5 to the 1D array. Then append column 6 and rows 1 through 6 to the 1D array. Finally the 1D array would look like B. <br>
> <br>
> A =[<br>
> 0 0 0 0 1 1<br>
> 0 0 0 0 1 1<br>
> 0 0 0 0 1 1<br>
> 0 0 0 0 1 1<br>
> 0 0 0 0 1 1<br>
> 0 0 0 0 0 1];<br>
> <br>
> B = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1];<br>
> <br>
> I would like this process to be automated because of the size of the matrix and the real matrix is not in any specific order. For example, columns 1 through 4 contain 4 of the necessary rows, but columsn 5, 6, 10 contain 8 of the necessary rows. I know how many rows I should take for each column. Also I can not use a sparse function to remove the padding because there are values that are zero and actually mean something. While other values are zeros and is just there for padding. <br>
> <br>
> Thank you in advanced.<br>
        <br>
If 'r' is a row vector giving the desired number of "circumferential locations" at each respective "longitudinal location", then do:<br>
<br>
B = A(bsxfun(@minus,r,(1:size(A,1)).')>=0).';<br>
<br>
Roger Stafford

Tue, 19 Apr 2011 19:37:04 +0000
Re: 2D array to 1D array
http://www.mathworks.com/matlabcentral/newsreader/view_thread/306469#832021
Brianne
Thanks a lot!!! It worked. <br>
<br>
"Roger Stafford" wrote in message <ioivcc$h56$1@fred.mathworks.com>...<br>
> "Brianne " <brianne.y.williams@aero.org> wrote in message <ioik84$mnc$1@fred.mathworks.com>...<br>
> > I have a matrix that is 9 x 52. Nine represents the maximum number of circumferential locations at a specificed longitudinal location around a model and 52 represents the longitudinal location along the model. For example, at longitudinal station #1 there are 4 circumferential values. At station #5 there are 8 circumferential values. However, MATLAB pads in zeros to make the matrix a square. <br>
> > <br>
> > My question is how to I grab those specific values out of the 2D array and place it into a 1D array? The reshape function will not work because the matrix dimension will be changing. <br>
> > <br>
> > For the purpose of my question I will use a simpler example. Assume A is a 6 x 6 matrix. For columns 1 through 4, I want to put the values of rows 1 through 4 into a 1D array. Then append column 5 and rows 1 through 5 to the 1D array. Then append column 6 and rows 1 through 6 to the 1D array. Finally the 1D array would look like B. <br>
> > <br>
> > A =[<br>
> > 0 0 0 0 1 1<br>
> > 0 0 0 0 1 1<br>
> > 0 0 0 0 1 1<br>
> > 0 0 0 0 1 1<br>
> > 0 0 0 0 1 1<br>
> > 0 0 0 0 0 1];<br>
> > <br>
> > B = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1];<br>
> > <br>
> > I would like this process to be automated because of the size of the matrix and the real matrix is not in any specific order. For example, columns 1 through 4 contain 4 of the necessary rows, but columsn 5, 6, 10 contain 8 of the necessary rows. I know how many rows I should take for each column. Also I can not use a sparse function to remove the padding because there are values that are zero and actually mean something. While other values are zeros and is just there for padding. <br>
> > <br>
> > Thank you in advanced.<br>
>         <br>
> If 'r' is a row vector giving the desired number of "circumferential locations" at each respective "longitudinal location", then do:<br>
> <br>
> B = A(bsxfun(@minus,r,(1:size(A,1)).')>=0).';<br>
> <br>
> Roger Stafford