Path: news.mathworks.com!not-for-mail
From: "Bruno Luong" <b.luong@fogale.findmycountry>
Newsgroups: comp.soft-sys.matlab
Subject: Re: add new field to structure
Date: Sat, 20 Apr 2013 06:58:08 +0000 (UTC)
Organization: FOGALE nanotech
Lines: 52
Message-ID: <kktea0$eml$1@newscl01ah.mathworks.com>
References: <kks1fm$g3a$1@newscl01ah.mathworks.com>
Reply-To: "Bruno Luong" <b.luong@fogale.findmycountry>
NNTP-Posting-Host: www-02-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1366441088 15061 172.30.248.47 (20 Apr 2013 06:58:08 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 20 Apr 2013 06:58:08 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 390839
Xref: news.mathworks.com comp.soft-sys.matlab:793950

"Michel Slivitzky" wrote in message <kks1fm$g3a$1@newscl01ah.mathworks.com>...
> I have a 224x1 structure "grid" which aleardy contains 9 fields
> I would like to add a new field and the corresponding 224 numerical data (which are in a vector)

>> s=struct('f', {0 0 0})

s = 

1x3 struct array with fields:

    f

>> a = [1 2 3];
>> c = num2cell(a)

c = 

    [1]    [2]    [3]


>> [s.newf] = deal(c{:})

s = 

1x3 struct array with fields:

    f
    newf


>> s(1)

ans = 

       f: 0
    newf: 1

>> s(2)

ans = 

       f: 0
    newf: 2

>> s(3)

ans = 

       f: 0
    newf: 3

% Bruno