Save Signals in Simulink

조회 수: 14 (최근 30일)
Zaucher . 2019년 3월 15일
답변: Zaucher . 2019년 3월 21일
Is it possible to store signal's in a simulink block? I work with CANoe and Simulink. The CANoe Singal Input Block send constantly with a Sample Rate from 100 Hz particular Signals (acceleration of a car). I want to store this Signals in a Block to calculate for example the minimum value over the whole data's.
I hope you understand my question.
Greetings from Germany

답변 (3개)

Munish Raj
Munish Raj 2019년 3월 18일
Hello Zaucher
To save information in simulink, you could write the information to a mat file.
The 'To File' block in simulink can be used for this.
The documentation for the 'To File' block can be found here.
To process the data after the the simulation is complete you could use the StopFcn callback.
The documentation for Model Callbacks can be found here.
All the lines of code in the StopFcn callback will be executed after the model is done executing. This would be an optimal time to perform functions on the entire saved data.
Alternatively , if you want to load from mat file, you could use the 'From file' block,
The documentation of the same can be found here.
Thank you
Munish Raj

Zaucher 2019년 3월 20일
Thank you for your answer,
it helps me a lot. But i have an other question. Currently I store the data via the toFile block in a .m file. The variable has a defined name "hunter_acceleration". I want to use this variable in another callback function (StopFcn), like you said. How do I get access to these variable?
In a seperate m.file i have all my math operation which one needs acces to the variable stored in the toFile block.
Greetings an Thanks a lot
  댓글 수: 1
Munish Raj
Munish Raj 2019년 3월 20일
In the begenning of the StopFcn callback ,you could use
This will load the variables in the .mat file into the workspace.
The name_of_file will be found in the ToFile block(double click the block to find the name of the file).
Now, you have access to the hunter_acceleration variable, which is also present in the MATLAB workspace.(MATLAB and simulink uses the same workspace).
In the StopFcn Callback, you can use the seperate .m file the same way you would use it from the MATLAB command line.
Any line of code can be written in the StopFcn Callback(or any callback).
I hope this solves your doubt
Thank you

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

Zaucher 2019년 3월 21일
Thank you for the quick answer. I dont know why it doesnt work.
For example:
In my toFile Block i have declared my Name File Name as:
in the toFile Block i wrote my function name into my StopFcn callback like
my_update (it is a m.file where i wrote my math operations)
in my my_update m.file is the following code:
function my_update
x = Hunter_Forward_Acceleration * 2;
is there any mistake i made?
Thank you


Help CenterFile Exchange에서 Configure and View Diagnostics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by