File I/O C S-function Example

버전 1.0.0.1 (9.22 KB) 작성자: Jarrod Rivituso
A simple C S-function which reads data from a file during simulation.
다운로드 수: 3.2K
업데이트 날짜: 2016/9/1

라이선스 보기

S-functions are used to create user defined blocks in Simulink. This S-function creates a block that reads data from a file incrementally at each time step of the Simulink simulation.
The S-function was written in C and uses the standard file I/O functions from the stdio.h library (fopen, fscanf, fclose). It is intended merely as an example.

The trickiest part of writing S-functions can sometimes be maintaining persistent data in subsequent calls to the S-function. This issue presents itself in this example. In order to read from the file throughout the simulation without closing and reopening the file each time step, the FILE pointer is stored in the PWork vector. This gives the S-function access to the FILE pointer at each step in the simulation.

In this S-function, the mdlStart function opens the file at the start of the simulation and the mdlTerminate function closes the file at the end. The mdlOutputs function is used to read data from the file at every time step.

To run the example:
1) Enter
mex -setup
at the MATLAB Command Prompt and select a compiler
2) Copy the attached files to the current MATLAB directory
3) Enter
mex cfileiosfun.c
to compile the S-function
4) Open the attached model and simulate.

인용 양식

Jarrod Rivituso (2024). File I/O C S-function Example (https://www.mathworks.com/matlabcentral/fileexchange/13438-file-i-o-c-s-function-example), MATLAB Central File Exchange. 검색됨 .

MATLAB 릴리스 호환 정보
개발 환경: R2006b
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux
카테고리
Help CenterMATLAB Answers에서 Block and Blockset Authoring에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!
버전 게시됨 릴리스 정보
1.0.0.1

Updated license

1.0.0.0