1
我想用一個匿名函數用於以下內容來創建一個function_handle:如何正確創建多變量分段函數的函數句柄?
f(x,y) = 1, if 2 <= x <= 3 and y = 1,
f(x,y) = 0, otherwise
我想我可能只是做:
f @(x,y) 1.*((x >= 2) && (x <= 3) & (y == 1));
當我試圖通過評估這個功能:f(ones(3,1),ones(3,1))
,我得到錯誤:
Operands to the
||
and&&
operators must be convertible to logical scalar values.
我還注意到,我的功能似乎正常工作時,我只輸入標x
和y
。 我的問題是:我如何正確定義我的函數句柄,以便它可以用於向量/數組?