MATLAB Answers

Setting the properties of an Object Array

Asked by Nicholas Dinsmore on 1 Oct 2012
Accepted Answer by Matt J

The documentation and experimentation make it clear that I can do this to get the property values of an array of objects:


The question is how can I do the reverse without major use of subsasgn. For example I want to be able to do something like the following


I just can't seem to make that work. I have tried many different permutations but nothing seems to work. Does any on have any thoughts on how to make that work.

I have tried the following with no success:

% suggestion from Stackoverflow


2 Answers

Answer by Matt J
on 1 Oct 2012
 Accepted answer


Nicholas Dinsmore on 1 Oct 2012

Matt, That is great thank you. Is there a way to do that in a single line of code?

Matt J
on 1 Oct 2012

If Array_of_property_values_to_assign is already a cell array, then you can just do


Otherwise, no, there is no way to do it in 1 line, except for fancy subsasgn methods.

per isakson
on 3 Oct 2012

- or write an appropriate version of deal.

Answer by Grzegorz Lippe
on 11 Jun 2013


this isn't working for me and I can't figure out what I'm doing wrong:

>> a = num2cell(1:3)
a = 
      [1]    [2]    [3]
>>[p(:).h_fP_star] = deal(a{:});
ans =
       3     3     3

Could anybody help?

  1 Comment

Matt J
on 11 Jun 2013



and show us the result.

Discover MakerZone

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

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!