How can I decide one struct to another one?

2 views (last 30 days)
I have struct s1 96 fields, each field contein 1 number, and the same struct s2 but with another numbers in fields. How can i create an array tat contein s1/s2 ? Thank you

Accepted Answer

Matt J
Matt J on 22 Mar 2022
Edited: Matt J on 23 Mar 2022
%structfun(@(a,b) a./b, s1,s2,'uni',0)
%EDIT:
s3=s1;
for fld=fieldnames(s1)'
fld=fld{1};
s3.(fld)=s1.(fld)/s2.(fld);
end
  3 Comments
Matt J
Matt J on 23 Mar 2022
Edited: Matt J on 23 Mar 2022
Ah well, just loop then.
s3=s1;
for fld=fieldnames(s1)'
fld=fld{1};
s3.(fld)=s1.(fld)/s2.(fld);
end

Sign in to comment.

More Answers (0)

Categories

Find more on Structures in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!