Read data in matlab functions for protected model Simulink

Hello,
I developped a Simulink model in which I call some Matlab function block. In these ones, I need to use some functions such as pwd or xlsread to read an entire xlsx/csv file once and get some table to use in matlab function later.
But I also need to protect my model and to use these functions I need to pass through :
coder.extrinsic
But it is not supported for the code generation.
Is there a easy way to fix this ? I didn't find a Simulink block to get some information such as the path of the executed model, and any other reading function has the same problem as xlsread.
Thank you very much in advance for your help.
Best regards.

12 Comments

I have to read the entire file once at the begin of the simulation. I don't see in the parameter of this block this possibility. Am I wrong ?
Is the file constant, or does the user need to be able to change it?
If it is constant, then postings I find say to read it and store it in a .mat file, as it is possible to generate code for load() of a .mat file (which if I understand correctly pretty much gets converted into C code that assigns values to the variables -- the loading ends up getting done statically instead of by reading from the disk.)
The file can be transform to a .mat file and there is 2 look up table to read for some matlab functions. This .mat file can change between two simulations but 99% of the time it wil be the same. But during a simulation the file is constant. Moreover, my matlab function read this file only once at the time t =0s.
So for me the load() function is the good option because it doesn't seem to need coder.extrinsic.
I imagine your solution with the load() function is still okay with what I said ? Best regards
Ah, if I understand the difference between load() and coder.load() https://www.mathworks.com/help/matlab/ref/load.html#bvlc6g4-1 then load() should indeed work at run-time, whereas coder.load() does what I described before of generating code for the exact set of data to be loaded.
Yes I think so. I will keep you informed when I will try it. Thank you very much
The load function, even if doesn't requrie the coder.extrinsic code line, is not supported also ... I tried with readtable but same thing. Do you know what matlab function can be used to read a table/csv/mat file and is compatible with the simulink coder ? Best regards.
  • coder.load loads data at compile time, not at run time. If you are generating MEX code or code for Simulink® simulation, you can use the MATLAB function load to load run-time values.
So, load() is documented as being supported for Simulink code generation. That was the case in R2016b as well, https://www.mathworks.com/help/releases/R2016b/simulink/slref/coder.load.html?searchHighlight=coder.load&s_tid=doc_srchtitle#moreabout which said "coder.load loads data at compile time, not at run time. If you are generating MEX code or code for Simulink® simulation, you can use the MATLAB function load to load run-time values."
Ok there is something I don't understand here. I want to protect my model through the protect() command to ask password for future user to open the model. You tell me that the load() function is not compatible to be used during a simulation ? So I have to find another solution to do it because my input data can change between two calls of the model (even if it should be very rare). Or maybe what I want to do is not realizable ?
I used coder.load which is the best solution I found until now. Thank you. I can't accept your answer because it is a comment of my question.
You tell me that the load() function is not compatible to be used during a simulation ?
No, I am telling you that the documentation says that you can use load() of a .mat file at run-time, and that the file can vary (though you do need to take care about which directory to look in for the file.)
I have no information about how any of this interacts with protect()
Ok thank you. I succeed to protect my model using coder.load finally, with a constant file in input. How to accept one of your comment as answer ?

Sign in to comment.

Answers (0)

Categories

Products

Release

R2016b

Asked:

on 27 Aug 2021

Community Treasure Hunt

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

Start Hunting!