How to split matrix into arrays without loop.

1 次查看(过去 30 天)
PL
PL =
2100 2100.5 -0.67
2100 2101 -0.17
2100 2101.5 0.33
2100 2102 0.83
2100 2102.5 1.33
2100 2103 1.83
2100 2103.5 2.33
2100 2104 2.83
2100 2104.5 3.33
2100 2105 3.83
2100 2105.5 4.33
2100 2106 4.83
2100 2106.5 5.33
2100 2107 5.83
2100 2107.5 6.33
2100 2108 6.83
2100 2108.5 7.33
2100 2109 7.83
2100 2109.5 8.33
2100 2110 8.83
2100 2099.5 -1.67
2100 2099 -2.17
2100 2098.5 -2.67
2100 2098 -3.17
2100 2097.5 -3.67
2100 2097 -4.17
2100 2096.5 -4.67
2100 2096 -5.17
2100 2095.5 -5.67
2100 2095 -6.17
2100 2094.5 -6.67
2100 2094 -7.17
2100 2093.5 -7.67
2100 2093 -8.17
2100 2092.5 -8.67
2100 2092 -9.17
2100 2091.5 -9.67
2100 2091 -10.17
2100 2090.5 -10.67
2100 2090 -11.17
2109.5 2110 -0.68
2109 2110 -0.18
2108.5 2110 0.32
2108 2110 0.82
2107.5 2110 1.32
2107 2110 1.82
2106.5 2110 2.32
2106 2110 2.82
2105.5 2110 3.32
2105 2110 3.82
2104.5 2110 4.32
2104 2110 4.82
2103.5 2110 5.32
2103 2110 5.82
2102.5 2110 6.32
2102 2110 6.82
2101.5 2110 7.32
2101 2110 7.83
2100.5 2110 8.33
2100 2110 8.83
2110.5 2110 -1.68
2111 2110 -2.18
2111.5 2110 -2.68
2112 2110 -3.18
2112.5 2110 -3.68
2113 2110 -4.18
2113.5 2110 -4.68
2114 2110 -5.18
2114.5 2110 -5.68
2115 2110 -6.18
2115.5 2110 -6.68
2116 2110 -7.18
2116.5 2110 -7.68
2117 2110 -8.18
2117.5 2110 -8.68
2118 2110 -9.18
2118.5 2110 -9.68
2119 2110 -10.18
2119.5 2110 -10.68
2120 2110 -11.18
2100 2099.5 -1.67
2100 2099 -2.17
2100 2098.5 -2.67
2100 2098 -3.17
2100 2097.5 -3.67
2100 2097 -4.17
2100 2096.5 -4.67
2100 2096 -5.17
2100 2095.5 -5.67
2100 2095 -6.17
2100 2094.5 -6.67
2100 2094 -7.17
2100 2093.5 -7.67
2100 2093 -8.17
2100 2092.5 -8.67
2100 2092 -9.17
2100 2091.5 -9.67
2100 2091 -10.17
2100 2090.5 -10.67
2100 2090 -11.17
2100 2109.5 8.33
2100 2109 7.83
2100 2108.5 7.33
2100 2108 6.83
2100 2107.5 6.33
2100 2107 5.83
2100 2106.5 5.33
2100 2106 4.83
2100 2105.5 4.33
2100 2105 3.83
2100 2104.5 3.33
2100 2104 2.83
2100 2103.5 2.33
2100 2103 1.83
2100 2102.5 1.33
2100 2102 0.83
2100 2101.5 0.33
2100 2101 -0.17
2100 2100.5 -0.67
2100 2100 -1.17
2100.5 2110 8.33
2101 2110 7.83
2101.5 2110 7.32
2102 2110 6.82
2102.5 2110 6.32
2103 2110 5.82
2103.5 2110 5.32
2104 2110 4.82
2104.5 2110 4.32
2105 2110 3.82
2105.5 2110 3.32
2106 2110 2.82
2106.5 2110 2.32
2107 2110 1.82
2107.5 2110 1.32
2108 2110 0.82
2108.5 2110 0.32
2109 2110 -0.18
2109.5 2110 -0.68
2110 2110 -1.18
2109.5 2110 -0.68
2109 2110 -0.18
2108.5 2110 0.32
2108 2110 0.82
2107.5 2110 1.32
2107 2110 1.82
2106.5 2110 2.32
2106 2110 2.82
2105.5 2110 3.32
2105 2110 3.82
2104.5 2110 4.32
2104 2110 4.82
2103.5 2110 5.32
2103 2110 5.82
2102.5 2110 6.32
2102 2110 6.82
2101.5 2110 7.32
2101 2110 7.83
2100.5 2110 8.33
2100 2110 8.83
>> size(PL)
ans =
160 3
>> series1 = [1:(size(PL,1)/8):size(PL,1),size(PL,1)]
series1 =
1 21 41 61 81 101 121 141 160
>> for i = 1: length(series1)-2
PL1(:,:,i) = PL(series1(i):series1(i+1)-1,:);
end
for i = length(series1)-1
PL1(:,:,i) = PL(series1(i):series1(i+1),:);
end
>> PL1
PL1(:,:,1) =
2100 2100.5 -0.67
2100 2101 -0.17
2100 2101.5 0.33
2100 2102 0.83
2100 2102.5 1.33
2100 2103 1.83
2100 2103.5 2.33
2100 2104 2.83
2100 2104.5 3.33
2100 2105 3.83
2100 2105.5 4.33
2100 2106 4.83
2100 2106.5 5.33
2100 2107 5.83
2100 2107.5 6.33
2100 2108 6.83
2100 2108.5 7.33
2100 2109 7.83
2100 2109.5 8.33
2100 2110 8.83
PL1(:,:,2) =
2100 2099.5 -1.67
2100 2099 -2.17
2100 2098.5 -2.67
2100 2098 -3.17
2100 2097.5 -3.67
2100 2097 -4.17
2100 2096.5 -4.67
2100 2096 -5.17
2100 2095.5 -5.67
2100 2095 -6.17
2100 2094.5 -6.67
2100 2094 -7.17
2100 2093.5 -7.67
2100 2093 -8.17
2100 2092.5 -8.67
2100 2092 -9.17
2100 2091.5 -9.67
2100 2091 -10.17
2100 2090.5 -10.67
2100 2090 -11.17
PL1(:,:,3) =
2109.5 2110 -0.68
2109 2110 -0.18
2108.5 2110 0.32
2108 2110 0.82
2107.5 2110 1.32
2107 2110 1.82
2106.5 2110 2.32
2106 2110 2.82
2105.5 2110 3.32
2105 2110 3.82
2104.5 2110 4.32
2104 2110 4.82
2103.5 2110 5.32
2103 2110 5.82
2102.5 2110 6.32
2102 2110 6.82
2101.5 2110 7.32
2101 2110 7.83
2100.5 2110 8.33
2100 2110 8.83
PL1(:,:,4) =
2110.5 2110 -1.68
2111 2110 -2.18
2111.5 2110 -2.68
2112 2110 -3.18
2112.5 2110 -3.68
2113 2110 -4.18
2113.5 2110 -4.68
2114 2110 -5.18
2114.5 2110 -5.68
2115 2110 -6.18
2115.5 2110 -6.68
2116 2110 -7.18
2116.5 2110 -7.68
2117 2110 -8.18
2117.5 2110 -8.68
2118 2110 -9.18
2118.5 2110 -9.68
2119 2110 -10.18
2119.5 2110 -10.68
2120 2110 -11.18
PL1(:,:,5) =
2100 2099.5 -1.67
2100 2099 -2.17
2100 2098.5 -2.67
2100 2098 -3.17
2100 2097.5 -3.67
2100 2097 -4.17
2100 2096.5 -4.67
2100 2096 -5.17
2100 2095.5 -5.67
2100 2095 -6.17
2100 2094.5 -6.67
2100 2094 -7.17
2100 2093.5 -7.67
2100 2093 -8.17
2100 2092.5 -8.67
2100 2092 -9.17
2100 2091.5 -9.67
2100 2091 -10.17
2100 2090.5 -10.67
2100 2090 -11.17
PL1(:,:,6) =
2100 2109.5 8.33
2100 2109 7.83
2100 2108.5 7.33
2100 2108 6.83
2100 2107.5 6.33
2100 2107 5.83
2100 2106.5 5.33
2100 2106 4.83
2100 2105.5 4.33
2100 2105 3.83
2100 2104.5 3.33
2100 2104 2.83
2100 2103.5 2.33
2100 2103 1.83
2100 2102.5 1.33
2100 2102 0.83
2100 2101.5 0.33
2100 2101 -0.17
2100 2100.5 -0.67
2100 2100 -1.17
PL1(:,:,7) =
2100.5 2110 8.33
2101 2110 7.83
2101.5 2110 7.32
2102 2110 6.82
2102.5 2110 6.32
2103 2110 5.82
2103.5 2110 5.32
2104 2110 4.82
2104.5 2110 4.32
2105 2110 3.82
2105.5 2110 3.32
2106 2110 2.82
2106.5 2110 2.32
2107 2110 1.82
2107.5 2110 1.32
2108 2110 0.82
2108.5 2110 0.32
2109 2110 -0.18
2109.5 2110 -0.68
2110 2110 -1.18
PL1(:,:,8) =
2109.5 2110 -0.68
2109 2110 -0.18
2108.5 2110 0.32
2108 2110 0.82
2107.5 2110 1.32
2107 2110 1.82
2106.5 2110 2.32
2106 2110 2.82
2105.5 2110 3.32
2105 2110 3.82
2104.5 2110 4.32
2104 2110 4.82
2103.5 2110 5.32
2103 2110 5.82
2102.5 2110 6.32
2102 2110 6.82
2101.5 2110 7.32
2101 2110 7.83
2100.5 2110 8.33
2100 2110 8.83
>>
I have matrix PL. I have to split matrix PL into 8 parts. I want to program without loop, if possible kindly help me.

采纳的回答

DGM
DGM 2021-8-25
You should be able to just do:
PL2 = permute(reshape(PL.',3,[],8),[2 1 3]);
to get the same result. Bear in mind that this assumes dim1 of the array is integer-divisible by 8. Otherwise, you'd have to pad it, or you could convert it to a cell array using mat2cell().

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by