필터 지우기
필터 지우기

Combine 2 column matrix into 1 column matrix

조회 수: 2 (최근 30일)
Phong Pham
Phong Pham 2015년 2월 16일
편집: Stephen23 2015년 2월 16일
I have a matrix A which contains x components, Note that A have multiple rows and columns.
Let's say
A=[ 1 2 3 4 0;
1.1 2.1 3.1 4.1 0;
1.2 2.2 3.2 4.2 0;
0 2.3 3.3 4.3 0;
0 2.4 3.4 4.4 0;
0 2.5 3.5 4.5 1.5;
0 2.6 3.6 4.6 1.6];
Now I want A to be
A=[ 1 2 3 4 ;
1.1 2.1 3.1 4.1 ;
1.2 2.2 3.2 4.2 ;
0 2.3 3.3 4.3 ;
0 2.4 3.4 4.4 ;
1.5 2.5 3.5 4.5 ;
1.6 2.6 3.6 4.6 ];
Note that the matrix is big so I cant use my vision to do so. I want to combine the one that has 0 as starting point (A(1,:)=0) to the one that has zero somewhere which is the first column and the condition is that the last point of first column is closer to the value of last column (you can see the last column has value of 1.5 which is closer to 1.2 that is why I combine them together)
Please helps. I am appreciated your opinions and helps.
  댓글 수: 2
Guillaume
Guillaume 2015년 2월 16일
You haven't explained very well what you want to do.
You say that 'B is same as A' and that you 'want A to be [..] same as B'. That would mean that A stays the same.
With the example you've given, it looks like you're removing the last column and if a row of that column is not 0, replace the first column of the same row with it. Is that what you want? Probably not, as it does not involve combining any matrix.
Image Analyst
Image Analyst 2015년 2월 16일
Clear as mud. Even after reading several times and looking at the example.

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

채택된 답변

Stephen23
Stephen23 2015년 2월 16일
편집: Stephen23 2015년 2월 16일
If you want to merge non-zero elements of the last column into the first column, then you can use this:
A = [1.0, 2.0, 3.0, 4.0, 0;...
1.1, 2.1, 3.1, 4.1, 0;...
1.2, 2.2, 3.2, 4.2, 0;...
0, 2.3, 3.3, 4.3, 0;...
0, 2.4, 3.4, 4.4, 0;...
0, 2.5, 3.5, 4.5, 1.5;...
0, 2.6, 3.6, 4.6, 1.6];
X = A(:,end)>0;
A(X,1) = A(X,end);
A(:,end) = [];
This gives A as
A =
1.0 2.0 3.0 4.0
1.1 2.1 3.1 4.1
1.2 2.2 3.2 4.2
0 2.3 3.3 4.3
0 2.4 3.4 4.4
1.5 2.5 3.5 4.5
1.6 2.6 3.6 4.6

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by