loading .mat files in a simulink user defined function

5 views (last 30 days)
Hello! I am working on some model validation and have built a 'Matlab function' block in Simulink. In the Matlab function I need to load some .mat files. The .mat files take and input value and return an output value that is used within the main Matlab function. The 'Matlab function' block is basically a copy of a .m file I have created and used before, (it works in matlab). Simulink has issues loading the .mat files however and I am not sure how to get around this problem. I assume this is because the .mat files are 'defined' in Matlab and not available to Simulink, though I am not sure why. Any ideas? Tips?

Answers (1)

Azzi Abdelmalek
Azzi Abdelmalek on 23 Jul 2014
You didn't post how you are downloading your file, I guess you have used the command
load filename
If your mat file contains, for example three variables x,y and z, add this code
data=load('file')
x=data.x
y=data.y
z=data.z
  3 Comments
Azzi Abdelmalek
Azzi Abdelmalek on 24 Jul 2014
Please, shows us how you are trying to load your data, and why you can't use
filename='your_mat_file'
data=load(filename)
John
John on 22 Aug 2014
the file 'your_mat_file' as in your example above is a [1 x 1 cfit] spline so when I use the commands
filename = 'my_mat_file' load 'filename'
Then I can use 'filename' to get values from the file as a function of inputs as follows
test = filename(5,17) test = 35.8
or
test = filename(1,234) test = 983.2
for example.
Simulink doesnt seem to understand that this mat. file is a fitted spline- like funciton.

Sign in to comment.

Categories

Find more on Simulink Functions in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!