delete columns in a struct array
5 ビュー (過去 30 日間)
古いコメントを表示
Hi!
I have a struct array E struct, attached, and I want to delete the columns of each struct that correspond to []: example E(1,5).{1,1}, E(1,9).{1,1}. Can you help me? thanks
0 件のコメント
採用された回答
Guillaume
2016 年 3 月 14 日
編集済み: Guillaume
2016 年 3 月 14 日
"I want to delete the columns of each struct". No, you want to delete the columns of the cell array, if present, contained in the 'bcd' field of each struct. It's important to use proper terminology so you can be understood. It also helps in finding out how to solve the problem:
for siter = 1:numel(E) %iterate over each structure
c = E(siter).bcd; %get cell array in field 'bcd' of structure
if iscell(c) %some structures don't have a cell array in the field
emptycell = cellfun(@isempty, c); %find empty columns of cell array
c(emptycell) = []; %delete empty cell
E(siter).bcd = c; %and put back in structure field
end
end
Or in a more compact form (but slightly more difficult to understand
for siter = 1:numel(E)
if iscell(E(siter).bcd)
E(siter).bcd(cellfun(@isempty, E(siter).bcd)) = [];
end
end
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Structures についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!