How to concatenate multi rows in matrix ?

1 回表示 (過去 30 日間)
hewaa mero
hewaa mero 2013 年 11 月 28 日
コメント済み: hewaa mero 2013 年 11 月 28 日
How to concatenate multi rows in matrix, for example I've a matrix 6X8
x= 1 1 1 1 1 1 1 1
2 2 2 2 2 2 2 2
3 3 3 3 3 3 3 3
4 4 4 4 4 4 4 4
5 5 5 5 5 5 5 5
6 6 6 6 6 6 6 6
the result like this
y = 1 1 1 1 1 1 1 1
2 2 2 2 2 2 2 2
3 3 3 3 3 3 3 3
4 4 4 4 4 4 4 4
y = 1 1 1 1 1 1 1 1
2 2 2 2 2 2 2 2
5 5 5 5 5 5 5 5
6 6 6 6 6 6 6 6
y = 3 3 3 3 3 3 3 3
4 4 4 4 4 4 4 4
5 5 5 5 5 5 5 5
6 6 6 6 6 6 6 6
tried concatenated row_row by this code below :
old=round(10*rand(6,8))
for n=1 :size(old)
for m=n+1:size(old)
newline = [old(n, :); old(m, :)]
end
end

回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2013 年 11 月 28 日
編集済み: Andrei Bobrov 2013 年 11 月 28 日
y = 1:6;
o = reshape(bsxfun(@times,kron(fliplr(~eye(3)),[1 1]),y)',1,[]);
out = repmat(reshape(o(o~=0),4,1,[]),1,7);
ADD
old = randi(40,6,8)
t = kron(fliplr(~eye(3)),[1 1])'>0
for jj = size(t,2):-1:1
out(:,:,jj) = old(t(:,jj),:);
end
  4 件のコメント
Andrei Bobrov
Andrei Bobrov 2013 年 11 月 28 日
see ADD part
hewaa mero
hewaa mero 2013 年 11 月 28 日
you mean I just use add part, and I used this part but answer not correct there 3 there matrix: out(:,:,1),out(:,:,2)again out(:,:,1), and out matrix is not ordered like that 1st part with 2nd part ,1st part with 3rd, 1st part with 4th,.....

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by