[請益]function輸入變數

作者: cos66666 (cos6666)   2019-12-26 01:26:50
我在M檔案中輸入以下函數
function y=gx(x)
y=2.*x+x.^2;
而執行過後不斷跑出
Not enough input arguments
Error in gx(line 2)
y=2.*x+x.^2
請問該如何更改才不會跑出Error??
作者: shuncheng (shuncheng)   2019-12-26 02:38:00
你直接compile function檔?
作者: cos66666 (cos6666)   2019-12-26 09:21:00
是阿 因為書上是這樣教的我是在script編譯的
作者: shuncheng (shuncheng)   2019-12-26 16:12:00
簡單的說 你寫好了這個程式 程式就看得懂這個函數了因此你要使用這個函數 舉例來說會這樣打x = 3; y = gx(x);你直接compile function檔 x沒變數宣告 當然會有錯誤
作者: sppmg (sppmg)   2019-12-26 22:37:00
應該說你如果是按圖形介面或f5執行(run),相當於在命令列打 gx() 所以沒給足夠參數。
作者: cos66666 (cos6666)   2019-12-27 14:09:00
感謝2位s大

Links booklink

Contact Us: admin [ a t ] ucptt.com