![](/img/trans.png)
[英]Error: operator *: nonconformant arguments (op1 is rxc, op2 is rxc )
[英]Why does this Gaussian function give nonconformant arguments error?
function m=gaussian(med, var, n)
if ( mod(n, 2)==0 )
n=n+1;
end;
med=double(med);
var=double(var);
med = min (max(-(n+1)/2, med), (n+1)/2);
m=zeros(1,n);
k1=(1/(2*pi*var)^0.5);
k2=-0.5.*((med-(1:n)).^2)./var;
m(1,1:n)=k1.*exp(k2);
輸出1
>> gaussian([101 2 ; 3 4], [4 301 ; 2 1], [2 2])
error: gaussian: operator /: nonconformant arguments (op1 is 1x1, op2 is 2x2)
error: called from
gaussian at line 13 column 5
>>
輸出2
>> gaussian([101 2 ; 3 4], [4 301 ; 2 1], 2)
error: gaussian: operator /: nonconformant arguments (op1 is 1x1, op2 is 2x2)
error: called from
gaussian at line 13 column 5
我不確定您想要的結果是什么,但是會收到該錯誤,因為您正在用[2x2]
矩陣對標量( [1x1]
尺寸)進行矩陣除法 。 請注意,您正在執行矩陣除法( /
運算符),而不是逐個元素除法( ./
運算符)。
octave:1> function m=gaussian(med, var, n)
> if ( mod(n, 2)==0 )
> n=n+1;
> end;
>
> med=double(med);
> var=double(var);
>
> med = min (max(-(n+1)/2, med), (n+1)/2);
>
> m=zeros(1,n);
>
> k1=(1/(2*pi*var)^0.5);
> k2=-0.5.*((med-(1:n)).^2)./var;
>
> m(1,1:n)=k1.*exp(k2);
> endfunction
octave:2> debug_on_error (1)
octave:3> gaussian ([101 2 ; 3 4], [4 301 ; 2 1], 2)
error: gaussian: operator /: nonconformant arguments (op1 is 1x1, op2 is 2x2)
error: called from
gaussian at line 13 column 5
stopped in gaussian at line 13
13: k1=(1/(2*pi*var)^0.5);
debug> (2*pi*var)
ans =
25.1327 1891.2388
12.5664 6.2832
debug> 1/(2*pi*var) # matrix division
error: gaussian: operator /: nonconformant arguments (op1 is 1x1, op2 is 2x2)
error: called from
gaussian at line 13 column 5
debug> 1./(2*pi*var) # your element by element division works
ans =
0.03978874 0.00052875
0.07957747 0.15915494
但是,這不是唯一的問題,因為以下行的減號運算符也有類似的問題:
error: gaussian: operator -: nonconformant arguments (op1 is 2x2, op2 is 1x3)
error: called from
gaussian at line 14 column 5
stopped in gaussian at line 14
14: k2=-0.5.*((med-(1:n)).^2)./var;
或者,函數可能不正確,並且由於錯誤地調用了函數而出現了這些錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.