数模论坛

 找回密码
 注-册-帐-号
搜索
热搜: 活动 交友 discuz
查看: 2786|回复: 4

help

[复制链接]
发表于 2004-2-3 17:15:16 | 显示全部楼层 |阅读模式
为什么我要自定义一个函数的时候会出现下面的句子啊??请问是什么问题呢??

??? Strings passed to EVAL cannot contain function declarations.

我根据书本的例子编写的,也不行么??是不是我的matlab有问题啊,我的matlab

每次打开来,窗口里面的文字是乱码,注销系统后就好了。这是什么问题啊,我用

的是 matlab 6.5.1,各位帮帮忙吧,谢谢
发表于 2004-2-4 07:23:06 | 显示全部楼层
最好把程序贴一部分出来
另外,我也用的matlab6.5.1是没有什么问题的

从错误信息估计有可能你在错误的地方用了function申明函数了
 楼主| 发表于 2004-2-5 00:39:15 | 显示全部楼层
^_^,谢谢,我还是新手,我只是想用一下function这个自定义函数的功能,

比如说 function[output1,output2]-funciton_example(input1.input2)
            output1=input2;
            output2=input1;
其实上面的第一句函数题头写完了,按下enter就出现那据错误信息了,说字符不能用在通过EVAL时,不能用function定义。

再次谢谢~~
发表于 2004-2-9 20:03:36 | 显示全部楼层
>> 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)
           %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.

    See also SCRIPT, RETURN, VARARGIN, VARARGOUT, NARGIN, NARGOUT,
             INPUTNAME, MFILENAME.
发表于 2004-2-9 20:06:13 | 显示全部楼层
以下是引用霁月在2004-2-4 16:39:15的发言:
^_^,谢谢,我还是新手,我只是想用一下function这个自定义函数的功能,

比如说 function[output1,output2]-funciton_example(input1.input2)
             output1=input2;
             output2=input1;
其实上面的第一句函数题头写完了,按下enter就出现那据错误信息了,说字符不能用在通过EVAL时,不能用function定义。

再次谢谢~~


对了,函数定义是在editor(在命令窗口中用edit可以进入)中编辑
您需要登录后才可以回帖 登录 | 注-册-帐-号

本版积分规则

小黑屋|手机版|Archiver|数学建模网 ( 湘ICP备11011602号 )

GMT+8, 2024-11-30 13:36 , Processed in 0.054146 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表