MATLAB deploytool simulink Undefined function 'load_system'

随声附和 提交于 2019-12-13 04:35:40

问题


I am using a MATLAB m file code which loads a simulink file, runs it and evaluats it so many times inside a complicated parallel loop.

It runs perfect at MATLAB environment. When compiling the code via deploytool command, installing it and running it from command line, I would have a difficult time.

At the line where it is loading the model,

mymodel= ... ;
load_system(mymodel);

I get the following error

C:\Program Files\mymain\application>Warning: Name is nonexistent or not a directory: model
> In path at 109
  In addpath at 86
  In run_main at 3
Warning: Name is nonexistent or not a directory: data
> In path at 109
  In addpath at 86
  In run_main at 4
Warning: Name is nonexistent or not a directory: graphics
> In path at 109
  In addpath at 86
  In run_main at 5
Starting parallel pool (parpool) using the 'local' profile ... connected to 2 workers.
Initializing ...
Undefined function 'load_system' for input arguments of type 'char'.

Error in run_main (line 40)


MATLAB:UndefinedFunction

I don't care about warnings (as I don't care about most of other MATLAB warnings) however I get error about not recognizing function to open a simulink model ('load_system') :

Undefined function 'load_system' for input arguments of type 'char'.

I did a search and I found the following questions:

load_system using MCR

Deployment of Simulink Models

The first link says

I just got confused: is deployment tools about compiling to C++ or to .NET ? Is is supposed to increase speed or becomming stand-alone is the only advantage?

The problem with both links is that they talk about strategy. But how to implement them? How can I compile a MATLAB code which uses load_system and sim command to load and simulate a model?

Can anybody bring step by step solution for a very simple example of a MATLAB code (m file) simulating a model and then compiling both of them?


回答1:


The first sentence of your documentation screen shot is the important one. As mentioned by @Navan (in a comment), Simulink functionality is not compatible with MATLAB Compiler. That is, any m-code that uses Simulink functinality (load_system, sim, etc) will not execute when using the MATLAB Compiler.

Assuming that you have access to Simulink Coder, and that your model doesn't contain functionality that prevents it from being converted to c-code, then your only option is to develop your application in two parts:

  1. With your Simulink model: Use Simulink Coder to create an executable from your model. There are several examples of doing this in the doc, including Using RSIM Target for Batch Simulations. There are various command line options for passing new parameter sets and inputs to the executable via a mat file. The results of the simulation (i.e what would normally be written to the MATLAB Workspace) gets written to a mat file created by the executable.
  2. Within you MATLAB code: replace all Simulink functionality with a call (typically using the system function, as shown in the linked example) to the executable created in step 1. Prior to this call you'll need to create a mat file with all your parameters in it; and after the call you'll want to read results from the mat file created by the executable.

It's not a trivial process, but is do-able.



来源:https://stackoverflow.com/questions/31282103/matlab-deploytool-simulink-undefined-function-load-system

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!