Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
add new field to structure

Subject: add new field to structure

From: Michel Slivitzky

Date: 19 Apr, 2013 18:13:10

Message: 1 of 2

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)

Subject: add new field to structure

From: Bruno Luong

Date: 20 Apr, 2013 06:58:08

Message: 2 of 2

"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

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us