Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.

1 回表示 (過去 30 日間)
function T_w_bed_out = BedHex(T_bed, T_w_bed_in, m_dot_w_bed)
global U_bed A_bed
Cp_w_bed = 10^3*(-1.35090E-11*T_bed^5 + 2.40993E-08*T_bed^4 - 1.71323E-05*T_bed^3 + 6.07609E-03*T_bed^2 - 1.07591*T_bed + 8.02982E01)*1E-3;
T_w_bed_out = T_bed + (T_w_bed_in - T_bed)*exp((-U_bed*A_bed)/(m_dot_w_bed*Cp_w_bed));
So I have the above function to be called when I have to use it according to it's respective variable T_w_bedA_out or T_w_bedD_out, it seems to have the above error message as mentioned in the Summary. However, when I placed an arbituary constant eg. T_w_bedA_out = 140 (or T_w_bedD_out), the code works but it's not the desired outcome that I want.
Sorry for the inconvenience caused but I am new to MATLAB and need help in figuring out what is going on in the code. Thank you in advance!
Edit:
I have used sz = size(T_w_bedA_out) to try to see where the problem is. When the function is called, I get sz = 0 0, and I get sz = 1 1 when the arbituary constant is used.

回答 (1 件)

Walter Roberson
Walter Roberson 2022 年 12 月 8 日
one of the global variables is not initialized.
  2 件のコメント
Yap Siong Seng Immanuel
Yap Siong Seng Immanuel 2022 年 12 月 16 日
編集済み: Yap Siong Seng Immanuel 2022 年 12 月 16 日
Sorry for replying late, however I have already initialized the require variables in another function above the function mentioned.
function mainprog
...
T_cw_cond_out = T_w_cond_out;
....
end
function T_w_cond_out = CondHex(T_cond, T_w_cond_in, m_dot_w_cond)
global U_cond A_cond
Cp_w_cond = 1E-3*10^3*(1.95664E-10*T_cond^5 - 3.36772E-07*T_cond^4 + 2.34408E-04*T_cond^3 - 8.21171E-02*T_cond^2 + 1.86089E+01*T_cond - 2.15617E+03);
T_w_cond_out = T_cond + (T_w_cond_in - T_cond)*exp((-U_cond*A_cond)/(m_dot_w_cond*Cp_w_cond));
end
This was the code that I use but for some reason the size of the matrix keeps giving me sz = 0 0.
Edit: I have tried to size T_cw_cond_out which gives me the error as stated in the last statement of this comment.
Walter Roberson
Walter Roberson 2022 年 12 月 16 日
編集済み: Walter Roberson 2022 年 12 月 16 日
You do not declare the variable as global inside mainprog . You have to declare as global in every function that wants to work with the variable.

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

カテゴリ

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

タグ

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by