help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: copying cs-lists with deviating fields


From: Mike Miller
Subject: Re: copying cs-lists with deviating fields
Date: Fri, 28 Aug 2015 12:44:39 -0400

On Fri, Aug 28, 2015 at 09:17:57 -0700, JokerOne wrote:
>  a(1)      =    set_only_these_fields_that_suit_to_the_structure(b) %?
>
> Maybe "setfields", but as far as I see, setfields does not fit my needs. I
> potentially could make the desired function on my own (by looping over both
> structures and check if the fieldnames agree), but I would like to ask first
> if there is anything already available.

Right, I think something like this is fairly generic and
straightforward for what you want to do:

  names = intersect (fieldnames (a(1)), fieldnames (b));
  for i = 1:numel (names)
    a(1) = setfield (a(1), names{i}, getfield (b, names{i}));
  endfor

There's nothing that does this as far as I know (maybe some wizardry
with subsref / subsasgn).

-- 
mike



reply via email to

[Prev in Thread] Current Thread [Next in Thread]