octave-maintainers
[Top][All Lists]
Advanced

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

Re: struct concatenation


From: Olaf Till
Subject: Re: struct concatenation
Date: Thu, 7 Jul 2016 11:01:57 +0200
User-agent: Mutt/1.5.23 (2014-03-12)

On Thu, Jul 07, 2016 at 09:31:23AM +0200, Julien Bect wrote:
> 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) ?

In the 'struct' package, there is a function 'structcat' which solves
this with binary code and for general dimensions.

Olaf

-- 
public key id EAFE0591, e.g. on x-hkp://pool.sks-keyservers.net

Attachment: signature.asc
Description: Digital signature


reply via email to

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