MATLAB Answers

Save Signals in Simulink

25 views (last 30 days)
Zaucher
Zaucher on 15 Mar 2019
Answered: Zaucher on 21 Mar 2019
Hello,
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

  0 Comments

Sign in to comment.

Answers (3)

Munish Raj
Munish Raj on 18 Mar 2019
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

  0 Comments

Sign in to comment.


Zaucher
Zaucher on 20 Mar 2019
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 Comment

Munish Raj
Munish Raj on 20 Mar 2019
Hello
In the begenning of the StopFcn callback ,you could use
load('name_of_file.mat')
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

Sign in to comment.


Zaucher
Zaucher on 21 Mar 2019
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:
Hunter_Forward_Accleration_2019-03-21-08_35_10.mat
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
load('Hunter_Forward_Accleration_2019-03-21-08_35_10.mat')
x = Hunter_Forward_Acceleration * 2;
plot(x)
end
is there any mistake i made?
Thank you

  0 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!