필터 지우기
필터 지우기

How can I remove empty cells from struct data?

조회 수: 58 (최근 30일)
Bob
Bob 2023년 4월 5일
댓글: Jon 2023년 4월 6일
How can I remove empty cells from struct data?
I have tried to use this but it didn't work.
Charge(Charge==0) = [];
  댓글 수: 2
Oguz Kaan Hancioglu
Oguz Kaan Hancioglu 2023년 4월 5일
You need to build for loop to check the filed of struct is empty or not. You can use this code.
k = 1;
for i = 1:length(Charge)
if ~isempty(Charge(i).Voltage_measured)
ChargeNew(k).Voltage_measured = Charge(i).Voltage_measured;
ChargeNew(k).Current_measured = Charge(i).Current_measured;
ChargeNew(k).Temperature_measured = Charge(i).Temperature_measured;
ChargeNew(k).Current_charge = Charge(i).Current_charge;
ChargeNew(k).Voltage_charge = Charge(i).Voltage_charge;
ChargeNew(k).Time = Charge(i).Time;
k = k + 1;
end
end
Bob
Bob 2023년 4월 6일
Thank you for your answer.

댓글을 달려면 로그인하십시오.

채택된 답변

Jon
Jon 2023년 4월 5일
fun = @(s) all(structfun(@isempty,s));
idx = arrayfun(fun,Charge)
Charge(idx)=[]; % remove the empty elements
  댓글 수: 3
Bob
Bob 2023년 4월 6일
Thank you for your answer
Jon
Jon 2023년 4월 6일
Your welcome

댓글을 달려면 로그인하십시오.

추가 답변 (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