Octave-'endfunction' 命令与 'endif' 匹配 [英] Octave-'endfunction' command matched by 'endif'

查看:142
本文介绍了Octave-'endfunction' 命令与 'endif' 匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我我的代码有什么问题?

Can someone tell me what's wrong with my code?

   sinlaw('?',150,30,39.8)
   parse error near line 30 of file 
   'endfunction' command matched by 'endif'

function [phi] = sinlaw (A,a,B,b)
If A==('?')
a=deg2rad(a)
b=deg2rad(b)
A=(B/sin(b))*sin(a) 
endif
if(a=='?')
a=deg2rad(asin((A/B)*sin(b)))
endif
endfunction

推荐答案

虽然语法检查抱怨 endif

随时此处测试它.

function [phi] = sinlaw ( A, a, B, b )

    if A == ( '?' )                                 %% this works, not the "If"
       a  = deg2rad( a )
       b  = deg2rad( b )
       A  = ( B / sin( b ) ) * sin( a ) 
    endif

    if ( a == '?' )
         a = deg2rad( asin( ( A / B ) * sin( b ) ) )
    endif

endfunction
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
sinlaw(  150, '?', 30, 39.8 )
sinlaw(  '?', 150, 30, 39.8 )

这篇关于Octave-'endfunction' 命令与 'endif' 匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆