필터 지우기
필터 지우기

how can i split matrix into two part?

조회 수: 132 (최근 30일)
sharifah shuthairah syed abdullah
댓글: Rounak Saha Niloy 2022년 10월 19일
i have this matrix
PP =
11 8 2 10 1 4 6 5 9 7 12 3
4 3 5 7 6 9 11 1 2 8 12 10
4 11 9 10 12 2 6 5 8 1 7 3
3 9 2 7 6 8 11 12 1 4 10 5
i want to split this matrix into to part
so code like this
v=2
p1=[PP(1:v,:)];
p2=[PP(PP-v+1:end,:)];
v=2 means that i want to split into two row..
the 1st and 2nd row is in p1, and the 3rd and 4th in p2..
for p1 i got the code correctly however for p2 i didnt get it right
i put v because if the matrix change to 6x6 or 10x10 , i want to change the value of v into what ever i want..
  댓글 수: 5
ACHAMMA JACOB
ACHAMMA JACOB 2019년 2월 7일
hello sir,
actually i am having a matrix 201x301. I need to spli it into 2 rows and N columns. how is it possible sir?
Shafiqur Rahman
Shafiqur Rahman 2020년 10월 16일
simply
pp=(5 row,5 clm)
p1=pp(1:2,:);
p2=pp(3:end,:)

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

채택된 답변

Stephen23
Stephen23 2019년 1월 12일
편집: Stephen23 2019년 1월 12일
p1 = PP(1:v,:);
p2 = PP(v+1:end,:);
Note that I got rid of the superfluous square brackets.
  댓글 수: 1
sharifah shuthairah syed abdullah
thank you so much.. i have been stuck several week on this part.. thank you so much..

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

추가 답변 (3개)

madhan ravi
madhan ravi 2019년 1월 12일
편집: madhan ravi 2019년 1월 12일
  댓글 수: 1
sharifah shuthairah syed abdullah
i try using the code u give.. the result show that its change the value inside the matrix..
for example
PP =
11 5 6 3 10 7 1 2 4 9 8 12
4 10 1 2 8 12 3 5 6 7 11 9
6 3 5 10 12 1 2 7 9 4 11 8
12 1 10 8 2 5 4 6 11 9 7 3
the result
P=reshape(PP,v,size(PP,2),[])
P(:,:,1) =
11 6 5 3 6 5 3 10 10 12 7 1
4 12 10 1 1 10 2 8 8 2 12 5
P(:,:,2) =
1 2 2 7 4 9 9 4 8 11 12 8
3 4 5 6 6 11 7 9 11 7 9 3

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


Fahimeh Yeganeh
Fahimeh Yeganeh 2020년 9월 29일
I have a matrix as below;
1 0.7494 -32.75 -25.375
2 0.91315 -9.875 -10.75
2 1 -3 -7.375
1 1.8799 -8.875 -5.875
2 2.29885 30.875 40.50
2 2.46570 -2.25 3.875
I would like to split it into 'n' number of matrices based on the variations in the first column. In the above example n=2.
Doese anyone know how I can do it in Matlab?
Thanks

Fahimeh Yeganeh
Fahimeh Yeganeh 2020년 9월 29일
I mean I would like to split it as the following 2 matrices
1 0.7494 -32.75 -25.375
1 1.8799 -8.875 -5.875
and
2 0.91315 -9.875 -10.75
2 1 -3 -7.375
2 2.29885 30.875 40.50
2 2.46570 -2.25 3.875
  댓글 수: 1
Rounak Saha Niloy
Rounak Saha Niloy 2022년 10월 19일
Use unique function to get the index of items from the first column. Now use that index to split your matrix.

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by