How can I read/write .txt file on Simulink environment?

조회 수: 13 (최근 30일)
Damdae
Damdae 2017년 2월 5일
댓글: Walter Roberson 2021년 8월 4일
As you might know, there is no block for reading or writing data to .txt format in Simulink model library. (PLEASE DO NOT tell me use .mat format instead of it)
So I firstly used Interpreted MATLAB Function containing fopen, fprintf, and fscanf codes inside.
However, I found that it triggers saving 0 values at initialization stage.
This lead me to think of using the S-function block, which seems to can handle initialization stage separately so that I can neglect the saving procedure at initialization stage.
Is there any source file or even a link that I'm looking for?

채택된 답변

Ankit Bhatnagar
Ankit Bhatnagar 2017년 2월 8일
There is no way available to write to a text file directly in Simulink. You can use the "To Workspace" block or "To File" (a .mat file) to store what data you want to.
Then with that data, you can use save() in Command Window to save the data to a text file as shown:
save File Data -ascii
  댓글 수: 1
Walter Roberson
Walter Roberson 2021년 8월 4일
You can also use MATLAB Function Block in Simulink to do saving

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Simulink Functions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by