将matlab内联命令转换为不同的命令

时间:2017-04-05 06:48:32

标签: c++ matlab

我在Matlab工作,我编写了以下脚本,意图导入Excel,但是当我运行Matlab C ++编码器时,它告诉我我的内联命令不受支持。

function f = moody(ed,Re)
if Re<0
 error(fprintf('Reynolds number = %f cannot be negative',Re));
elseif Re<2000
 f = 64/Re;  return      %  laminar flow
end
if ed>0.05
 error(fprintf('epsilon/diameter ratio = %f is not on Moody chart',ed));
end
findf =  inline('1.0/sqrt(f)+2.0*log10(ed/3.7+2.51/(Re*sqrt(f)))','f','ed','Re');
fi = 1/(1.8*log10(6.9/Re+(ed/3.7)^1.11))^2;   %  initial guess at f
dfTol = 5e-6;
f = fzero(findf,fi,optimset('TolX',dfTol,'Display','off'),ed,Re);`

如何使用匿名函数或arrayfun命令重写findf = inline命令,以便编译器可以工作?

1 个答案:

答案 0 :(得分:0)

findf = @(f,ed,Re)1.0 / sqrt(f)+ 2.0 * log10(ed / 3.7 + 2.51 /(Re * sqrt(f)))