How to assign values to MV Targets of MPC object from cell array

4 ビュー (過去 30 日間)
Bill Tubbs
Bill Tubbs 2022 年 10 月 6 日
コメント済み: Bill Tubbs 2023 年 1 月 25 日
I'm having a tough time trying to assign 3 values to the parameters of an mpc object.
Here is my MPC object with it's current values for the MV targets:
extractfield(mpcobj.MV, "Target")
ans =
1×3 cell array
{[38.6500]} {'nominal'} {'nominal'}
According to this answer, I should be able to assign values to a struct like this:
[mpcobj.MV.Target] = {99, 10, 'nominal'};
But I get this error message:
Error using mpc/subsasgn (line 511)
Scalar structure required for this assignment.
I tried this:
setfield(mpcobj.MV, "Target", {99, 10, 'nominal'});
but get the same error. I notice in the documentation there is an example like this:
MPCobj.DisturbanceVariables(1).ScaleFactor = 10;
MPCobj.DisturbanceVariables(2).ScaleFactor = 5;
MPCobj.DisturbanceVariables(3).ScaleFactor = 20;
Is there no way to assign these in one go (without a for loop)?

採用された回答

Emmanouil Tzorakoleftherakis
Emmanouil Tzorakoleftherakis 2023 年 1 月 25 日
編集済み: Emmanouil Tzorakoleftherakis 2023 年 1 月 25 日
You could specify values individually
mpcobj.MV(1).Target=99;
mpcobj.MV(2).Target=10;
or you could do it in one line as follows:
mpcobj.MV = struct(Target={99;10;'nominal'});
Hope that helps
  3 件のコメント
Emmanouil Tzorakoleftherakis
Emmanouil Tzorakoleftherakis 2023 年 1 月 25 日
You don't really need a for loop for 3 values, but if you want to do it in one line, I guess the following should work:
mpcobj.MV = struct(Target={99;10;'nominal'});
I updated my answer as well
Bill Tubbs
Bill Tubbs 2023 年 1 月 25 日
Thanks. This is the answer I was looking for. The reason I would have needed a for loop is because the cell array is of indefinite length.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeController Creation についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by