From: SM on
Hi everybody,

I want to combine rows in a matrix in following way:
A=[a b c d
e f g h
i j k l];
if j=1
y=[a b c d];

if j=2
y=[a e b f c g d h];

if j=3
y=[a e i b f j c g k d h l];
.....
is it possible to do this in matlab?

thanks for any advice.
From: Sean on
"SM " <khanmoradi(a)gmail.com> wrote in message <hsb4o0$8ra$1(a)fred.mathworks.com>...
> Hi everybody,
>
> I want to combine rows in a matrix in following way:
> A=[a b c d
> e f g h
> i j k l];
> if j=1
> y=[a b c d];
>
> if j=2
> y=[a e b f c g d h];
>
> if j=3
> y=[a e i b f j c g k d h l];
> ....
> is it possible to do this in matlab?

Sure, just about anything is possible in MATLAB!

%I'm going to use numbers instead of letters.
A = ceil(10*rand(3,4));
Ap = A';
j = 1; %can be 1, 2 or 3 for this 'A' matrix
y = Ap(1:j*4)';
From: SM on
> A = ceil(10*rand(3,4));
> Ap = A';
> j = 1; %can be 1, 2 or 3 for this 'A' matrix
> y = Ap(1:j*4)';
Actually, this only ordered the rows. What I want is something different.

Assume A = ceil(10*rand(3,4)) generates the following matrix:
A=[4 10 6 8
4 7 7 3
3 5 10 9]
in case j=2, I want the following outcome:
y= [4 4 10 7 6 7 8 3]
(while the provided code gives y=[4 10 6 8 4 7 7 3])...

is it possible to do this in matlab?
From: Oleg Komarov on
"SM " <khanmoradi(a)gmail.com> wrote in message <hsbgq8$ct7$1(a)fred.mathworks.com>...
> > A = ceil(10*rand(3,4));
> > Ap = A';
> > j = 1; %can be 1, 2 or 3 for this 'A' matrix
> > y = Ap(1:j*4)';
> Actually, this only ordered the rows. What I want is something different.
>
> Assume A = ceil(10*rand(3,4)) generates the following matrix:
> A=[4 10 6 8
> 4 7 7 3
> 3 5 10 9]
> in case j=2, I want the following outcome:
> y= [4 4 10 7 6 7 8 3]
> (while the provided code gives y=[4 10 6 8 4 7 7 3])...
>
> is it possible to do this in matlab?

A = [4 10 6 8
4 7 7 3
3 5 10 9];
j=2;

Out = reshape(A(1:j,:),1,[])
Out =
4 4 10 7 6 7 8 3

Oleg