簡體   English   中英

Matlab fplot:沒有足夠的輸入參數

[英]Matlab fplot: not enough input arguments

我剛剛開始學習 Matlab,我一直在尋找解決方案。

基本上,我只需要 fplot 一個函數,然后對以后的問題進行更多操作。

fplot(@(x) myfunc);

function y = myfunc(x)
    y = (x^3) - (4 .* x^2) - 1
end

產生這個錯誤

Warning: Function behaves unexpectedly on array inputs. To improve performance,
properly vectorize your function to return an output with the same size and shape as
the input arguments. 
> In matlab.graphics.function.FunctionLine>getFunction
  In matlab.graphics.function.FunctionLine/updateFunction
  In matlab.graphics.function.FunctionLine/set.Function_I
  In matlab.graphics.function.FunctionLine/set.Function
  In matlab.graphics.function.FunctionLine
  In fplot>singleFplot (line 234)
  In fplot>@(f)singleFplot(cax,{f},limits,extraOpts,args) (line 193)
  In fplot>vectorizeFplot (line 193)
  In fplot (line 163)
  In HWA1_2 (line 1) 
Warning: Error updating FunctionLine.

 The following error was reported evaluating the function in FunctionLine update: Not
 enough input arguments.

當我單獨使用 fplot 時它會起作用。

fplot((x^3)-(4*x^2)-1)

如果有人能指出我做錯了什么,我將不勝感激。 我需要將它定義為函數的原因是因為我稍后需要對其進行更多操作。

您調用 fplot 的語法是問題所在,而不是您的函數。 如果您要傳遞一個簡單的函數句柄,只需使用:

fplot(@myfunc)

您使用的語法是您創建匿名函數的方式,但您忘記在等式中包含x 你也可以這樣寫並得到相同的結果:

fplot(@(x) myfunc(x))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM