永发信息网

matlab中function函数的具体用法

答案:3  悬赏:50  手机版
解决时间 2021-01-29 05:20
  • 提问者网友:回忆在搜索
  • 2021-01-29 00:20
如题,在线等
最佳答案
  • 五星知识达人网友:煞尾
  • 2021-01-29 00:26
1.新建一个m文件,把function函数复制进去;然后保存(名称应该是自动生成的,即为sinh.m,不过最好不要用和系统中的文件一样的名称,可以先help查看一下matlab是否有和sinh重复的名称,若有的话,得把function函数改个名称),保存的地址为当前工作目录。

2.在命令窗口调用function函数:

sinh(5)
全部回答
  • 1楼网友:山君与见山
  • 2021-01-29 01:43
FUNCTION Add new function. New functions may be added to MATLAB's vocabulary if they are expressed in terms of other existing functions. The commands and functions that comprise the new function must be put in a file whose name defines the name of the new function, with a filename extension of '.m'. At the top of the file must be a line that contains the syntax definition for the new function. For example, the existence of a file on disk called STAT.M with: function [mean,stdev] = stat(x) %STAT Interesting statistics. n = length(x); mean = sum(x) / n; stdev = sqrt(sum((x - mean).^2)/n); defines a new function called STAT that calculates the mean and standard deviation of a vector. The variables within the body of the function are all local variables. See SCRIPT for procedures that work globally on the work- space. A subfunction that is visible to the other functions in the same file is created by defining a new function with the FUNCTION keyword after the body of the preceding function or subfunction. For example, avg is a subfunction within the file STAT.M: function [mean,stdev] = stat(x) %STAT Interesting statistics. n = length(x); mean = avg(x,n); stdev = sqrt(sum((x-avg(x,n)).^2)/n); %------------------------- function mean = avg(x,n) %MEAN subfunction mean = sum(x)/n; Subfunctions are not visible outside the file where they are defined. Normally functions return when the end of the function is reached. A RETURN statement can be used to force an early return.
  • 2楼网友:青灯有味
  • 2021-01-29 00:51
我了个神啊,为了能用好matlab,我劝楼主还是稍微学学英语吧。其实也不用特别学,把help里不认识的英文单词查一查就差不多了。 要是连这点耐性都没有的话,建议楼主还是放弃编程吧。
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯