How to assign array values to object.object.property at once using deal?

19 ビュー (過去 30 日間)
Abdolkarim Mohammadi
Abdolkarim Mohammadi 2020 年 9 月 13 日
編集済み: Matt J 2020 年 9 月 13 日
I know that it is possible to assign the values of an array to object.property using deal(). Is it possible to do such thing for object.object.property? I am specifically working with SimulationInput objects, where the variables property of this object is itself an object and has a property named value, and I want to do something like the following:
SimIn = repmat (Simulink.SimulationInput, [NumRows, NumCols]);
[SimIn] = SimIn.setVariable ('VariableName', 0);
SimIn.Variables.Value = Data(:);
or
[SimIn(:).Variables.Value] = deal (Data(:));

採用された回答

Matt J
Matt J 2020 年 9 月 13 日
編集済み: Matt J 2020 年 9 月 13 日
No, you would have to do it in 2 steps,
[Variables.Value] = deal (Data(:));
[SimIn(:).Variables] = deal (Variables);
  1 件のコメント
Matt J
Matt J 2020 年 9 月 13 日
編集済み: Matt J 2020 年 9 月 13 日
If you find you need to do this frequently, however, it probably means your choice of data organization is sub-optimal for your problem. You should probably have array-valued properties, rather than an array of objects.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by