Setting the properties of an Object Array
조회 수: 6 (최근 30일)
이전 댓글 표시
The documentation and experimentation make it clear that I can do this to get the property values of an array of objects:
Array_of_property_values=[Object_Array(:).Property];
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
[Object_Array(:).Property]=Array_of_property_values_to_assign;
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:
[Object_Array(1:2).Property]=[10,20];
% suggestion from Stackoverflow
[Object_Array(:).Property]=deal(Array_of_property_values_to_assign);
댓글 수: 0
채택된 답변
Matt J
2012년 10월 1일
args=num2cell(Array_of_property_values_to_assign);
[Object_Array(:).Property]=deal(args{:});
댓글 수: 3
추가 답변 (1개)
Grzegorz Lippe
2013년 6월 11일
Hello,
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{:});
>>[p.h_fP_star]
ans =
3 3 3
Could anybody help?
댓글 수: 1
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!