How can I use the 'From File'-block with simulation targets other than rsim?

In the documentation it says the 'From File'-block is usable with double, one-dimensional, real signals, if using any simulation target other than rsim. I tried it in several simple models, but the data contained in the specified .mat file at compile time is simply hard coded in the generated code. The compiled model will obviously give the same results no matter which data is contained in the specified file.
I know it is generally possible to use for example the C-API to interact with the executable, but it seems a lot of trouble for the simple and available method to provide .mat files.

댓글 수: 3

When you say the data is hard coded, do you mean the name of the file or the data contained in the file?
I mean the actual data contained in the file, not the file name.
Are you trying to generate code for this? I don't think this will work since you would be trying to generate code that reads MAT files which are designed to be used only in MATLAB. When you read simulation target that may mean something like accelerator mode versus normal mode.
If you have xPC there is a generic from file block there that you may be able to work with or you can use input ports and write code to read and write from a file.

댓글을 달려면 로그인하십시오.

 채택된 답변

Kaustubha Govind
Kaustubha Govind 2013년 2월 6일

1 개 추천

I agree with Ryan. Reading/Writing MAT-files requires MATLAB run-time libraries, which is why the code generated for standalone execution doesn't contain code for the From File block. However, if you have a fixed format of the MAT-file and are okay with using MATLAB run-time libraries, you can write C-code to read your files using the MAT-file API and to use the Legacy Code Tool to generate a (code-generation compliant) S-function that you can use in place of the From File block.

댓글 수: 1

Patrick
Patrick 2013년 2월 8일
편집: Patrick 2013년 2월 8일
Thanks for your reply. It does of course make sense that Matlab runtime libraries are necessary to read .mat files. It is odd though, it is possible to log to .mat files with grt target and others. It seems to me the separation between MATLAB and Simulink is not as clear as suggested. Anyway, as we're using the Matlab Compiler Runtime anyway in our application, this solution suits us well. It would be desirable if this would be documented somewhere accessible in the documentation. Explicitly the information in the Code Generation Block Support table is wrong.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Simulink Coder에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by