Clear Filters
Clear Filters

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

2 views (last 30 days)
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?

Answers (1)

Nirmal Gunaseelan
Nirmal Gunaseelan on 11 Aug 2011
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 Comments
Pat Finder
Pat Finder on 11 Aug 2011
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 on 12 Aug 2011
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).

Sign in to comment.

Categories

Find more on Simulink Functions in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!