How to write a For function using values from a table ?

8 ビュー (過去 30 日間)
Rami Altam
Rami Altam 2018 年 3 月 28 日
コメント済み: Rami Altam 2018 年 3 月 28 日
My equation is:
y(1) = FOPT -(55930.4 - 330502.*x(1) - 3.18673E6.*x(2) + 344393.*x(3) + 471232.*x(4) + 1.58821E6.*x(5) - 156.186.*x(6));
I want to create a For function and substitute FOPT of a value from a table in the Matlab named FOPT.
Thank you.

回答 (1 件)

Walter Roberson
Walter Roberson 2018 年 3 月 28 日
y = NameOfTable.FOPT - (55930.4 - 330502.*x(1) - 3.18673E6.*x(2) + 344393.*x(3) + 471232.*x(4) + 1.58821E6.*x(5) - 156.186.*x(6));
All of the x references are scalars, so the expression in () is a scalar, and a scalar can be subtracted from a matrix without difficulty.
Note: if you are trying to fit parameters against a model, then unless you have strong constraints on your x values, there is not going to be a unique answer, since a change in any one of the x() values can be exactly compensated by a change in another value. For example an increase of 1 in x(1) can be exactly compensated by a decrease of 330502 / 156.186 = 2116.07954618212 in x(6) or an increase of 344393/330502 = 1.04203000284416 in x(3)
  3 件のコメント
Walter Roberson
Walter Roberson 2018 年 3 月 28 日
編集済み: Walter Roberson 2018 年 3 月 28 日
FOPT_values = NameOfTable.FOPT;
num_FOPT = length(FOPT_values);
y = zeros(num_FOPT, 1);
for FOPT_idx = 1 : num_FOPT
FOPT = FOPT_values(FOPT_idx);
y(FOPT_idx) = FOPT -(55930.4 - 330502.*x(1) - 3.18673E6.*x(2) + 344393.*x(3) + 471232.*x(4) + 1.58821E6.*x(5) - 156.186.*x(6));
end
... But this is a waste of time, since you can use the simple code
y = NameOfTable.FOPT - (55930.4 - 330502.*x(1) - 3.18673E6.*x(2) + 344393.*x(3) + 471232.*x(4) + 1.58821E6.*x(5) - 156.186.*x(6));
This does substitute FOPT from the table named NameOfTable
Rami Altam
Rami Altam 2018 年 3 月 28 日
Thank you

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

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by