필터 지우기
필터 지우기

Elegant way of "sending to the next row" in a matrix

조회 수: 3 (최근 30일)
Matt
Matt 2015년 9월 10일
편집: Stephen23 2015년 9월 10일
Hello,
I have a 1x36 matrix that I want to cut in bits. In my specific case I want to obtain a 6x6 matrix from this 1x36 matrix. Every 6 column of the original 1x36 matrix I want to go to a next row.
How can I do this in an elegant way?
Thanks!

채택된 답변

Anthony Poulin
Anthony Poulin 2015년 9월 10일
I have not the same result and using a transpose I think that I get what you want.
A=1:10;
B=reshape(A, [5,2])'
So, B =
1 2 3 4 5
6 7 8 9 10
  댓글 수: 1
Stephen23
Stephen23 2015년 9월 10일
편집: Stephen23 2015년 9월 10일
Note that you should use the non-conjugate transpose .' rather than a simple '.
In fact it is a good habit to always use the non-conjugate transpose unless you specifically need the complex conjugate.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Anthony Poulin
Anthony Poulin 2015년 9월 10일
Hello,
Do you try to use the "reshape" function?
  댓글 수: 2
Matt
Matt 2015년 9월 10일
Yes, but it doesn't give me what I want. For example if I have the following matrix (as per Matlab example):
A = 1:10;
If I reshape it with this command:
B = reshape(A,[5,2]);
It will give me:
1 3 5 7 9
2 4 6 8 10
But what I want is:
1 2 3 4 5
6 7 8 9 10
Hamoon
Hamoon 2015년 9월 10일
편집: Hamoon 2015년 9월 10일
B=reshape(A,[5,2])
means B will be a (5*2) matrix, you're doing something wrong Matt, just clear your workspace variables and try again. as Anthony said you'll get the result you want using:
A=1:10;
B=reshape(A,[5,2]);
C=B';
C is what you want, and B is a (5*2) matrix
B =
1 6
2 7
3 8
4 9
5 10
C =
1 2 3 4 5
6 7 8 9 10

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by