how to split a 4x3 matrix in half
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
i have a 4x3 matrix that i need to split in half
arr1 = [1 2 3 4;5 6 7 8;9 10 11 12]
i need it to be
[1 2;5 6;9 10]
0 Kommentare
Antworten (3)
Torsten
am 7 Okt. 2022
If the number of columns of arr1 is divisible by 2:
arr1 = [1 2 3 4;5 6 7 8;9 10 11 12];
arr1_half = arr1(:,1:size(arr1,2)/2)
1 Kommentar
dpb
am 7 Okt. 2022
Bearbeitet: dpb
am 7 Okt. 2022
And depending on which way one wants to go, if odd then use either
arr1_half = arr1(:,1:fix(size(arr1,2))/2);
or
arr1_half = arr1(:,1:ceil(size(arr1,2))/2);
Either of those is general to handle both even and odd number of columns once a decision is made as to which way to round, up or down.
Ghazwan
am 7 Okt. 2022
Newarr1=arr1(:,1:length(arr1(1,:))/2)
%Note that the number of columns has to be even
0 Kommentare
Image Analyst
am 7 Okt. 2022
This is just very basic indexing. To learn other fundamental concepts, invest 2 hours of your time here:
0 Kommentare
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!