how to split a table to multiple table?
조회 수: 1 (최근 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!