How to: Make a simulink block to read in a data file?
1 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
回答(1 个)
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 个评论
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 Exchange 中查找有关 Interactive Model Editing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!