How can I remove empty cells from struct data?

57 次查看(过去 30 天)
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
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

请先登录,再进行评论。

采纳的回答

Jon
Jon 2023-4-5
fun = @(s) all(structfun(@isempty,s));
idx = arrayfun(fun,Charge)
Charge(idx)=[]; % remove the empty elements
  3 个评论

请先登录,再进行评论。

更多回答(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