필터 지우기
필터 지우기

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 CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by