フィルターのクリア

delete columns in a struct array

6 ビュー (過去 30 日間)
pamela sulis
pamela sulis 2016 年 3 月 14 日
編集済み: Guillaume 2016 年 3 月 14 日
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

採用された回答

Guillaume
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 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by