matlab中function 函数怎么用?

如题所述

问题描述:例如在命令窗口中 function
Number=recrgb(Image,Image_HSV,h,w)电脑就会提示:Function
业,但是在我的机子上运行的时候,我的matlab不认识load函数,我
很郁闷,我是2007的版本,你的如果版本高,应该可以认识load函数
件和所用图片放到matlab运行时所在的文件夹中,然后在command
window里运行Main即可,但是还有一点,因为你的程序处理的是mat格
式的数据。所以得把图片转化成mat格式。这部分代码我给你写,如
下:x=imread('pself2_51.jpg');save
FinalPosition.mat;这样就可以把图片保存成mat格式了。
版,应该能吧,
答案2:: M函数除了直接用函数名调用之外,也可以进行参数传
递,使得Matlab应用更加方便。M函数文件以function开头,格式为
function 输出变量 = 函数名称(输入变量)语句;例
如:%eg_1f.mfunction s=f(m)s=0for n=1:ms=s+1/n/n;end
保存为eg_1f.m,然后在指命窗口执行;;eg_1f(100)ans =
1.6350
答案3:: 你要新建一个script,把函数输进去,然后调用它就好了
recrgb(Image,Image_HSV,h,w) 追问 不好意思,我是新手,再麻
烦下,新建script输入函数后,是直接在命令窗口输入
recrgb(Image,Image_HSV,h,w)这个吗? 回答 把你上面这段复制到
script里面就好了
:::::::::::::::::::请参考以下相关问题::::::::::::::::::::
:::::::::::::::::::请参考以下相关问题::::::::::::::::::::
:::::::::::::::::::请参考以下相关问题::::::::::::::::::::
:::::::::::::::::::请参考以下相关问题::::::::::::::::::::
:::::::::::::::::::请参考以下相关问题::::::::::::::::::::
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2018-04-27
m文件函数是Matlab中的子函数,其格式为:function[输出参数列表]=函数名(输入参数列表)函数体举个例子,编写一个求自变量X的正弦值的m函数,如下:function y=mysin(x)y=sin(x);% 函数体此时在Matlab命令窗口输入若下内容时>>x=pi/2;>>y=mysin(x)Matlab便会调用y.m文件子函数,计算sin值,并给出结果为>>y=1例子有点简单,自己琢磨编写更强大的函数吧,注学习快乐!你觉得有帮助,别忘了采纳(⊙o⊙)哦!]本回答被网友采纳
第2个回答  2013-10-29
用.m文件来定义就行了: 比如:function y=num(a,b); y=a+b; 定义好后,保存为mum_1.m文件 比如你要计算2+3;就直接在command window里面输入num_1(2+3)=就行了;]
第3个回答  2013-10-28
M函数除了直接用函数名调用之外,也可以进行参数传递,使得Matlab应用更加方便。M函数文件以function开头,格式为function 输出变量 = 函数名称(输入变量)语句;例如:%eg_1f.mfunction s=f(m)s=0for n=1:ms=s+1/n/n;end保存为eg_1f.m,然后在指命窗口执行>>eg_1f(100)ans = 1.6350]
第4个回答  2013-10-28
输入:help function就会出现帮助! 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) %AVG 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.  See also script, return, varargin, varargout, nargin, nargout,  inputname, mfilename. Reference page in Help browser doc function]