Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: problem concatenating structs
Date: Mon, 24 Nov 2008 23:18:02 +0000 (UTC)
Organization: Lunds Universitet
Lines: 60
Message-ID: <ggfcna$cuq$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1227568682 13274 172.30.248.38 (24 Nov 2008 23:18:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 24 Nov 2008 23:18:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 5707
Xref: news.mathworks.com comp.soft-sys.matlab:502976


Hi, 
I have some problems concatenating structs.
Here is a minimal example

% fill out a struct
a.a=1;
a.b=2;
a.c=3;
a(1).d=4; 
% copy this, and add another field 
b=a;
b.e=5;
% copy the first one (don't want to destroy it...)
c=a;
c(1)=b;    % no no did not work, results in:
??? Subscripted assignment between dissimilar structures.

c=b;        % did work
% to me this is somewhat strange, 
% especially in the light that the following works

a(2).f=6:  % works fine:

a = 
1x2 struct array with fields:
    a
    b
    c
    d
    f

a(1)
ans = 
    a: 1
    b: 2
    c: 3
    d: 4
    f: []

> a(2)
ans = 
    a: []
    b: []
    c: []
    d: []
    f: 6

In reality I am using Jos' excellent FEX contribution CATSTRUCT:

D=C(k);
D.newfield=xyz;
%etc
C(k)=catstruct(C(k),D);   % fails

CATSTRUCT works as expected but because there is an index to C the line fails.

Any ideas how to solve this?

Lars