Forwarding to help list.
-------- Message transféré --------
Le 07/07/2016 à 09:23, c. a écrit :
> Hi,
>
> Say you have two struct variables
>
>>> s1
> s1 =
>
> scalar structure containing the fields:
>
> a: 1x1 scalar
> b: 1x1 scalar
>
>>> s2
> s2 =
>
> scalar structure containing the fields:
>
> c: 1x1 scalar
> d: 1x1 scalar
>
> and I want to create a new struct s that contains all fields of both.
> what would be a clean way of doing this?
>
> All I came up with for the moment was cycling over s1 and s2 and assigning
> each field to s, is there a better way?
here one possible way:
C = [fieldnames(s1) struct2cell(s1); fieldnames(s2) struct2cell(s2)];
s = struct (C'{:});
I don't know it it exists somewhere, but perhaps could this be turned
into a function name fieldcat (same as horzcat, vertcat) ?
@++
Julien