當我們在使用Matlab的時候,因需求要進行定義函數,有些朋友還不熟悉操作方法?下面一起去看看Matlab定義函數的詳細操作教程,相信你會喜歡的。
Matlab定義函數的詳細操作教程文章源自四五設計網-http://www.wasochina.com/48474.html
方法一:通過inline函數定義函數文章源自四五設計網-http://www.wasochina.com/48474.html
打開matlab,在命令行窗口中輸入“f=inline(‘5*x+1′,’x’)”,按回車鍵創建f(x)=5*x+1內聯函數,如圖所示:文章源自四五設計網-http://www.wasochina.com/48474.html
文章源自四五設計網-http://www.wasochina.com/48474.html
輸入“x=3;f(x)”,按回車鍵,可以得到f(x)等于16,如圖所示:文章源自四五設計網-http://www.wasochina.com/48474.html
文章源自四五設計網-http://www.wasochina.com/48474.html
方法二:匿名函數定義文章源自四五設計網-http://www.wasochina.com/48474.html
在命令行窗口中輸入“f=@(x)5*x+3”,按回車鍵定義函數f=@(x)5*x+3,如圖所示:文章源自四五設計網-http://www.wasochina.com/48474.html
文章源自四五設計網-http://www.wasochina.com/48474.html
輸入“x=2;f(x)”,按回車鍵,得到結果13,如圖所示:文章源自四五設計網-http://www.wasochina.com/48474.html
方法三:創建m函數
在matlab中點擊新建,選擇函數,如圖所示:
可以看到已創建了m函數,可在腳本文件中調用函數,如圖所示:
各位小伙伴們,看完上面的精彩內容,都清楚Matlab定義函數的詳細操作了吧!


評論