How to concatenate multi rows in matrix ?

1 次查看(过去 30 天)
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 个评论
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 CenterFile Exchange 中查找有关 Logical 的更多信息

标签

尚未输入任何标签。

Community Treasure Hunt

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

Start Hunting!

Translated by