フィルターのクリア

How to: Make a simulink block to read in a data file?

2 ビュー (過去 30 日間)
Pat Finder
Pat Finder 2011 年 8 月 11 日
I posted this to the general newsgroup, but no replies.
I have several situations where we have data in a column separated fields in a file.
I want to start using simulink because it provides an automatic visual understanding of the processing steps.
There are methods for creating a simulink block to read in a *.mat file, but I cannot figure out how to make a simulink block that reads in an ASCII file, and provides the data as column vectors: one column per entry.
Can someone please provide an example of how this would be done?

回答 (1 件)

Nirmal Gunaseelan
Nirmal Gunaseelan 2011 年 8 月 11 日
I am not aware of a block in Simulink that can read from a normal ASCII file (you could potentially write your own Level-2 MATLAB file S-function). There might be an easier way to do this by using MATLAB scripts (that could use TEXTREAD or related functions).
This MATLAB script can then be called in the model initialization section so that the data is available in the workspace before simulation starts.
Alternatively this script could write to a MAT-file (and not have any variables in the workspace) and you could use Simulink's From-file block to read in the data during simulation.
  2 件のコメント
Pat Finder
Pat Finder 2011 年 8 月 11 日
I noted the method for reading in from a *.mat file, but
that would be an engineering work-around.
It is surprising you cannot wrap a script in a Simulink block,
so that it prompts the user for a filename, and read it in.
So, you say I need to learn about something called a Level-2 S-function?
Nirmal Gunaseelan
Nirmal Gunaseelan 2011 年 8 月 12 日
There is also something called a MATLAB-function block (http://www.mathworks.com/help/toolbox/simulink/ug/f6-106261.html) that you can mask and read in a file name. A script can then be called from this block and the outputs could be the data from the file read in through the script. Would that work in your case?
I was considering code-generation options in my previous answer and code-generation would not be supported using MATLAB-function block at all times (many functions are supported though).

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSimulink Functions についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by