how to split a table to multiple table?

조회 수: 1 (최근 30일)
Jennifer Arellana
Jennifer Arellana 2021년 4월 2일
댓글: Jennifer Arellana 2021년 4월 6일
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
dpb 2021년 4월 2일
In MATLAB that is an array or a matrix, not a table...just for nomenclature.

댓글을 달려면 로그인하십시오.

채택된 답변

dpb
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
Jennifer Arellana
Jennifer Arellana 2021년 4월 6일
@dpb Thank you for your answer! the command "reshape" worked very well but I have another problem with this command. The problem is the order that the matrix have, please check this link:
I did another question about this problem and i gave a test data and the codes that i am using, if you run it in matlab you can notice that the order in the values in the new matrix is different to the old matrix but i want that the both has the same order.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

jannat alsaidi
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

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by