how to split a table to multiple table?
3 ビュー (過去 30 日間)
古いコメントを表示
For example, I have the next table with dimension 16x4:
CT = [
196 146 154 244;
317 129 140 224;
246 256 314 161;
333 292 245 183;
296 246 222 293;
291 138 174 174;
229 227 164 166;
176 115 184 237;
305 316 128 158;
234 345 211 142;
313 330 135 315;
262 208 286 172;
305 316 128 158;
196 146 154 244;
313 330 135 315;
296 246 222 293
];
And I want to split it in subtables each one with a dimension of 4x4. How can i do it?
1 件のコメント
採用された回答
dpb
2021 年 4 月 2 日
>> CT=reshape(CT,4,4,[])
CT(:,:,1) =
196 296 305 305
317 291 234 196
246 229 313 313
333 176 262 296
CT(:,:,2) =
146 246 316 316
129 138 345 146
256 227 330 330
292 115 208 246
CT(:,:,3) =
154 222 128 128
140 174 211 154
314 164 135 135
245 184 286 222
CT(:,:,4) =
244 293 158 158
224 174 142 244
161 166 315 315
183 237 172 293
>>
Address each 4x4 slice as
X=CT(:,:,i);
for i=1,2,3,4
Alternatively, you could just increment rows by indexing as
>> for i=1:4:size(CT,1)
CT(i:i+3,:), end
ans =
196 146 154 244
317 129 140 224
246 256 314 161
333 292 245 183
ans =
296 246 222 293
291 138 174 174
229 227 164 166
176 115 184 237
ans =
305 316 128 158
234 345 211 142
313 330 135 315
262 208 286 172
ans =
305 316 128 158
196 146 154 244
313 330 135 315
296 246 222 293
>>
その他の回答 (1 件)
jannat alsaidi
2021 年 4 月 2 日
you can use this way to split CT,
CT = [
196 146 154 244;
317 129 140 224;
246 256 314 161;
333 292 245 183;
296 246 222 293;
291 138 174 174;
229 227 164 166;
176 115 184 237;
305 316 128 158;
234 345 211 142;
313 330 135 315;
262 208 286 172;
305 316 128 158;
196 146 154 244;
313 330 135 315;
296 246 222 293
]
a=size(CT);
r=1;
n=1;
while n<(1+a(2))
k(:,:,n)=CT(r:a(2)*n,1:a(2))
r=r+4;
n=n+1;
end
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!