首页 \ 问答 \ 从Matlab函数运行Simulink(Run Simulink from Matlab function)

从Matlab函数运行Simulink(Run Simulink from Matlab function)

我正在使用FastRestart运行Simulink,因为我需要多次启动和停止模拟更改参数。 当我从主脚本运行Simulink时,没有问题。 但是,只要我使脚本成为一个函数,以便我可以为不同的输入数据运行它,我就会得到一个与Simulink明显相关的错误,而不是在函数中看到Matlab工作区。

更确切地说,假设sfile是我的Simulink文件,然后在Matlab中初始化我需要的所有变量之后运行以下行:

load_system(sfile);
set_param(sfile,'FastRestart','on');
set_param(sfile,'SaveFinalState','on');
set_param(sfile,'SaveCompleteFinalSimState','on');
set_param(sfile,'SimulationCommand','update');

在最后一行,我得到了Simulink无法识别mdl.tStep (这是时间步长)的错误,因为mdl不是公认的结构。 事实上,如果我从主脚本运行Simulink,一切都很好。

现在,在过去,我会用

options = simset('SrcWorkspace','current');

但是,我认识的专家建议我反对simset (因为它可能会在将来被弃用),并鼓励我使用set_param 。 我已经在线查找了set_param的选项,但是我找不到Matlab工作区的设置。

任何帮助将不胜感激。 先谢谢你!


I am running Simulink using FastRestart, as I need to start and stop the simulation multiple times changing parameters. When I run Simulink from the main script, there are no problems. However, as soon as I make the script a function so that I can run it for different input data, I get an error that is clearly related to Simulink not seeing the Matlab workspace within the function.

To be more precise, say sfile is my Simulink file, then I run the following lines AFTER having initialized all variables I need in structures in Matlab:

load_system(sfile);
set_param(sfile,'FastRestart','on');
set_param(sfile,'SaveFinalState','on');
set_param(sfile,'SaveCompleteFinalSimState','on');
set_param(sfile,'SimulationCommand','update');

At the last line, I get the error that Simulink does not recognize mdl.tStep (which is the time step), as mdl is not a recognized structure. In fact, it is and if I run Simulink from the main script everything is fine.

Now, in the past, I would have used

options = simset('SrcWorkspace','current');

However, an expert I know has advised me against simset (as it may get deprecated in the future) and encouraged me to use set_param instead. I have looked up the options for set_param on-line, but I could not find the setting for the Matlab workspace.

Any help would be greatly appreciated. Thank you in advance!


原文:https://stackoverflow.com/questions/42697878
更新时间:2023-07-08 18:07

最满意答案

在试图找出忽略某些东西的原因时,使用git check-ignore命令通常很有用:

$ git check-ignore --verbose some/file.txt
.gitignore:1:some   some/file.txt

输出可以这样解释:

如果指定了--verbose ,则输出是以下形式的一系列行:

<source> <COLON> <linenum> <COLON> <pattern> <HT> <pathname>

<pathname>是要查询的文件的路径, <pattern>是匹配模式, <source>是模式的源文件, <linenum>是该源中模式的行号。 如果图案包含! 前缀或/后缀,它将保留在输出中。 当引用core.excludesfile文件配置的文件时, <source>将是绝对路径,或者在引用.git/info/exclude或每个目录的排除文件时,相对于存储库根目录。


When trying to figure out why something is ignored, it is often useful to use the git check-ignore command:

$ git check-ignore --verbose some/file.txt
.gitignore:1:some   some/file.txt

The output can be interpreted like so:

If --verbose is specified, the output is a series of lines of the form:

<source> <COLON> <linenum> <COLON> <pattern> <HT> <pathname>

<pathname> is the path of a file being queried, <pattern> is the matching pattern, <source> is the pattern’s source file, and <linenum> is the line number of the pattern within that source. If the pattern contained a ! prefix or / suffix, it will be preserved in the output. <source> will be an absolute path when referring to the file configured by core.excludesfile, or relative to the repository root when referring to .git/info/exclude or a per-directory exclude file.

相关问答

更多
  • 在试图找出忽略某些东西的原因时,使用git check-ignore命令通常很有用: $ git check-ignore --verbose some/file.txt .gitignore:1:some some/file.txt 输出可以这样解释: 如果指定了--verbose ,则输出是以下形式的一系列行: 是要查询的文件的路径, 是 ...
  • 看了很多,我发现问题是通过访问GitHub并查看.gitignore文件,它在node_modules/的开头有一个非常奇怪的字符,但由于某种原因它没有出现在Sublime Text上。 现在它正确地忽略了该文件夹。 After looking a lot around I found the issue by going to GitHub and looking at the .gitignore file, it was having a really weird character at the b ...
  • 这是一个子模块。 要删除它,请执行以下操作: 从.gitmodules文件中删除相关行 从.git / config中删除相关部分 运行git rm --cached path_to_submodule(没有尾部斜杠) 提交并删除现在未跟踪的子模块文件。 It is a submodule. to remove it do the following: Delete relevant line from the .gitmodules file Delete relevant section from .g ...
  • 该图标表示:嵌套的git存储库。 含义:当你执行git add * ,你添加了嵌套git repo angular2-webpack-starter的顶层文件夹,将其记录为gitlink ( 父repo中的特殊条目 ,作为表示嵌套repo树的SHA1) 如果你真的想要包含angular2-webpack-starter的内容,你需要在``angular2-webpack-starter / .git`子文件夹中删除,并删除gitlink,然后重新添加文件夹: git rm --cached angular2 ...
  • 我遇到了同样的问题,即使我已经使用这个遥控器很长一段时间了,我最近没有改变任何东西。 我认为它与Github最近的制动和减速有关,事实上,他们已经在他们的Twitter账户上证实了这一点: https : //twitter.com/githubstatus/status/717464295454470145 我们的系统正在通过队列积压工作。 与此同时,新的推送可能需要一些时间才能显示在http://GitHub.com上 。 希望提交将很快出现在Github上:) I'm experiencing the ...
  • 只需添加目录中的所有内容,并将github与您的文件夹同步。 git add * git commit -m "removed a folder" git push origin master Just add everything in that is in your directory right now and have github sync with your folder. git add * git commit -m "removed a folder" git push origin ...
  • 它( bsg-services )是一个子模块 。 (参见“ 这个灰色git图标是什么? ”) 你需要: 通过首先进入该文件夹来添加/提交(并从该子仓库推送), ( bsg-services内的git状态会告诉你更多) 然后回到父回购(你在哪里),添加,提交和推送。 您将在bsg-services内完成的提交将修改父repo索引中的gitlink条目 。 所以你需要两个推动: 一个从子模块repo到它的上游repo(一个git remote -v应该告诉你) 一个来自父repo,以记录新的gitlink S ...
  • 首先检查你的状态和分支: git status git branch 如果您没有看到以* 开头的分支 ,则表示您正在分离的HEAD分支中工作 。 如果是这种情况,只需将主分支重置为当前HEAD并再次推送: git checkout -B master @ git push OP jebmarcus 在评论中确认在主分支上,并且状态清晰: 当我今天早上刷新回购时,一切都恢复了 这一定是GitHub方面的一个小故障。 GitHub上存在连接问题(8月3日发生了“轻微服务中断” - GitHub状态消息 )。 ...
  • 您已将更改提交到存储库的本地克隆。 如果你想在GitHub上看到那个提交,你需要首先git push它git push到那里。 You committed that change to the local clone of the repository. If you want to see that commit on GitHub, you'll need to git push it there first.
  • 在github上创建一个新的存储库(参见Github主页上的“New repository”按钮) 将此存储库添加为远程: git remote add origin url/provided/by/github 推送到此存储库: git push origin master Create a new repository on github (cf the "New repository" button on Github main page) Add this repository as a remot ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)