how to split a table to multiple table?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Jennifer Arellana
am 2 Apr. 2021
Kommentiert: Jennifer Arellana
am 6 Apr. 2021
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 Kommentar
Akzeptierte Antwort
dpb
am 2 Apr. 2021
>> 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
>>
Weitere Antworten (1)
jannat alsaidi
am 2 Apr. 2021
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 Kommentare
Siehe auch
Kategorien
Mehr zu Logical 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!