八度 - ' endfunction这样'命令匹配' endif'

时间:2017-09-18 21:53:38

标签: octave

有人可以告诉我我的代码有什么问题吗?

   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

1 个答案:

答案 0 :(得分:1)

虽然语法检查与endif

相匹配

问题实际上在If...错字

随意test it here

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 )