使用Matlab导入另一个.m文件 [英] Using Matlab to import another .m file

查看:1617
本文介绍了使用Matlab导入另一个.m文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Matlab很陌生.我已经在.m文件中定义了一个函数,我想在另一个.m文件中的该.m文件中使用该函数,并且想从命令窗口中运行最后一个.m文件的内容.

I'm quite new to Matlab. I've defined a function inside a .m file, I want to use that function in that .m file inside another .m file, and I want to run the contents of that last .m file from the command window.

我应该如何实现这一目标?

How should I go about accomplishing this?

编辑-为澄清起见,我在a.m中有一个功能a,在b.m中有一个脚本,该脚本在a.m中使用了功能a.我想从命令窗口在b.m中运行此脚本,但不确定如何执行. (作为补充,如果需要,我可以将b.m中的脚本完全转换为函数)

EDIT- for clarification, I have one function a inside a.m, and a script inside b.m that uses the function a inside a.m. I would like to run this script inside b.m from the command window, but am not sure how to do so. (as a side note, I can totally convert the script in b.m into a function if need be)

编辑-现在,我只需要知道如何导入/加载matlab文件即可!

EDIT- right now I just need to know how to import/load a matlab file and that is it!!!

推荐答案

原则上,MATLAB提倡每个.m文件使用 one 函数.您可以从另一个.m文件和MATLAB命令行中调用该函数.

In principle, MATLAB advocates the use of one function per .m file. You can call such a function from another .m file and from the MATLAB command line.

您可以在一个.m文件中定义多个功能,但是只能从其他.m文件或命令行中访问第一个(或最外层")功能.其他功能被视为帮助程序"功能,只能在此特定的.m文件内部调用.

You can define multiple functions in one .m file, but only the first (or 'outermost') function can be accessed from other .m files or the command line. The other functions are treated as 'helper' functions that may be called only inside this particular .m file.

这篇关于使用Matlab导入另一个.m文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆