delete columns in a struct array

6 次查看(过去 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

采纳的回答

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 CenterFile Exchange 中查找有关 Structures 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by