How do I remove individual columns from each cell in cell array?

2 ビュー (過去 30 日間)
lil brain
lil brain 2022 年 2 月 27 日
回答済み: Voss 2022 年 2 月 27 日
Hi,
I have this cell array "baskets_data" where each cell contains a matrix that is 21 columns long.
baskets_data =
19×1 cell array
{1617×21 cell}
...
For every cell in this cell array, I want to select 9 pre-specified columns and leave out the rest. Namely, 1-3, 8-10 and 15-17.
I have written this code:
for i = 1:length(baskets_data)
baskets_xyz = baskets_data{i}(:,[1:3,8:10,15:17]);
end
But as a result I only get a baskets_xyz = 979×9 cell array.
How can I get the cell array to look as follows:
baskets_xyz =
19×1 cell array
{1617×9 cell}
...
Thank you!

採用された回答

Voss
Voss 2022 年 2 月 27 日
load('baskets_data.mat');
disp(baskets_data);
{1617×21 cell} { 846×21 cell} {3812×21 cell} { 530×21 cell} {5463×21 cell} { 601×21 cell} { 998×21 cell} {1125×21 cell} { 645×21 cell} { 955×21 cell} {1747×21 cell} { 965×21 cell} { 546×21 cell} {1211×21 cell} {3023×21 cell} { 941×21 cell} { 915×21 cell} {2942×21 cell} { 979×21 cell}
baskets_xyz = cell(size(baskets_data));
for i = 1:numel(baskets_data)
baskets_xyz{i} = baskets_data{i}(:,[1:3,8:10,15:17]);
end
disp(baskets_xyz);
{1617×9 cell} { 846×9 cell} {3812×9 cell} { 530×9 cell} {5463×9 cell} { 601×9 cell} { 998×9 cell} {1125×9 cell} { 645×9 cell} { 955×9 cell} {1747×9 cell} { 965×9 cell} { 546×9 cell} {1211×9 cell} {3023×9 cell} { 941×9 cell} { 915×9 cell} {2942×9 cell} { 979×9 cell}

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by