how can i split matrix into two part?
Ältere Kommentare anzeigen
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 Kommentare
sharifah shuthairah syed abdullah
am 12 Jan. 2019
Stephen23
am 12 Jan. 2019
Note that in MATLAB square brackets are a concatenation operator. In your code the square brackets are totally superfluous, and you should get rid of them.
sharifah shuthairah syed abdullah
am 12 Jan. 2019
ACHAMMA JACOB
am 7 Feb. 2019
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
am 16 Okt. 2020
simply
pp=(5 row,5 clm)
p1=pp(1:2,:);
p2=pp(3:end,:)
Akzeptierte Antwort
Weitere Antworten (3)
madhan ravi
am 12 Jan. 2019
Bearbeitet: madhan ravi
am 12 Jan. 2019
Don’t think of naming variables dynamically ( https://www.mathworks.com/matlabcentral/answers/304528-tutorial-why-variables-should-not-be-named-dynamically-eval#answer_274740 )
v=2;
P=reshape(PP,v,size(PP,2),[])
Fahimeh Yeganeh
am 29 Sep. 2020
0 Stimmen
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
am 29 Sep. 2020
0 Stimmen
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 Kommentar
Rounak Saha Niloy
am 19 Okt. 2022
Use unique function to get the index of items from the first column. Now use that index to split your matrix.
Kategorien
Mehr zu MATLAB finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!