フィルターのクリア

Creating a function with endless errors

1 回表示 (過去 30 日間)
Vignesh Sella
Vignesh Sella 2018 年 12 月 4 日
編集済み: madhan ravi 2018 年 12 月 4 日
function [A2, V_inj, N, A2_tot] = OrfG(mdot, x)
%function
global d
global rho
global k
global deltap
A2 = pi*(d^2/4);
V_inj = sqrt((2*deltap)/(k*rho));
n_temp = mdot /(rho*V_inj*A2);
if x == 0
y = 0;
else
y = 1;
end
N = ceil(n_temp) + y;
A2_tot = N*A2;
end
Then I run
[q, w, r, t] = OrfG(1.53, 0)
I see
>> OrfG(1.53, 0)
Error using /
Matrix dimensions must agree.
Error in OrfG (line 18)
n_temp = mdot /(rho*V_inj*A2);
if I change the code to
n_temp = mdot ./(rho*V_inj)*A2);
and run the same code it shows me a bunch of empty matrices.
  1 件のコメント
KSSV
KSSV 2018 年 12 月 4 日
Why you want to use global? Try to avoid it.

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

回答 (2 件)

KSSV
KSSV 2018 年 12 月 4 日
YOu have to define the global variables...
global d
global rho
global k
global deltap
As you have not defined them,, they will be taken as empty i.e [].

madhan ravi
madhan ravi 2018 年 12 月 4 日
編集済み: madhan ravi 2018 年 12 月 4 日
Don't use global variables it's a bad practise , learn to parameterize functions.
See Parameterize function to better understand
d = somevalue;
rho= somevalue;
k= somevalue;
deltap= somevalue;
[A2, V_inj, N, A2_tot] = OrfG(mdot, x,d,rho,k,deltap) % function call just paramterize
function [A2, V_inj, N, A2_tot] = OrfG(mdot, x,d,rho,k,deltap)
%function
A2 = pi*(d^2/4);
V_inj = sqrt((2*deltap)/(k*rho));
n_temp = mdot /(rho*V_inj*A2);
if x == 0
y = 0;
else
y = 1;
end
N = ceil(n_temp) + y;
A2_tot = N*A2;
end

カテゴリ

Help Center および File ExchangeStructured Data and XML Documents についてさらに検索

タグ

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by