Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

diff_struct.m 950 B

12345678910111213141516171819202122232425262728293031323334353637
  1. function diffS = diff_struct(oldS, newS)
  2. % S = apply_struct(S, newS)
  3. % Give a "parent struct" and then apply a new struct that
  4. % overwrites matching elements of the old struct and adds
  5. % elements missing from the old struct.
  6. % see also diff_struct
  7. diffS = struct();
  8. fname = fieldnames(newS);
  9. oldfname = fieldnames(oldS);
  10. if ~isequaln(oldS, newS)
  11. for fx = 1:numel(fname)
  12. thisfield = fname{fx};
  13. if ~any(strcmp(thisfield,oldfname))
  14. % This is a new field
  15. diffS.(thisfield) = newS.(thisfield);
  16. elseif ~isequaln(newS.(thisfield), oldS.(thisfield))
  17. % They are not equal
  18. if isstruct(newS.(thisfield)) && numel(newS.(thisfield))==1
  19. diffS.(thisfield) = utils.diff_struct(oldS.(thisfield), newS.(thisfield));
  20. elseif isstruct(newS.(thisfield)) % numel > 1
  21. error('Cannot diff struct arrays.')
  22. else
  23. diffS.(thisfield) = newS.(thisfield);
  24. end
  25. else
  26. % nothing here?
  27. end
  28. end
  29. else
  30. diffS = [];
  31. end
  32. end