Matlab如何编函数脚本,如何编写具有与Matlab脚本兼容的函数定义的...

如果我这样写:

clc

clear

close all

format long

fprintf( 1, 'Starting...

' )

function results = do_thing()

results = 1;

end

results = do_thing()

并使用Octave运行它,它可以正常工作:

Starting...

results = 1

但是,如果我尝试使用Matlab 2017b运行它,则会抛出此错误:

Error: File: testfile.m Line: 13 Column: 1

Function definitions in a script must appear at the end of the file.

Move all statements after the "do_thing" function definition to before the first local function

definition.

然后,如果我按以下方式修复错误:

clc

clear

close all

format long

fprintf( 1, 'Starting...

' )

results = do_thing()

function results = do_thing()

results = 1;

end

它可以在Matlab上正常工作:

Starting...

results =

1

但是现在,它不再使用Octave:

Starting...

error: 'do_thing' undefined near line 8 column 11

error: called from

testfile at line 8 column 9

如何解决此问题而不必为函数do_thing()创建单独的专有文件?

此问题是否在某些较新版本的Matlab(2019a)中得到解决?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值