Importing a matrix in Simulink, extracting rows and interpolate
Mostra commenti meno recenti
Hello,
I have spent a good amount of hours searching for the answer to my problem on this website, I hope this post doesn't replicate another one.
I have a matlab function which loads a data file, searches the lines of interest in the matrix depending on inputs and interpolates using interp1. It works very well. However, when I input it in a Matlab function bloc in Simulink, it doesn't work. First error is the "importdata" which doesn't work. Then, the sign "==" for dynamic calculation like in: table = table( table(:,1) == MN , :); (where MN is an input) Eventually the "interp1" function doesn't seem to work ( underlined in red but since the function freezes before I can't say).
Any good way to solve this problem?
Also, I have tried the "from workspace" but then I don't care about the time parameter because I just want my matrix (it is absolutely not time dependent) and I want to play on its values.
Thanks
Risposta accettata
Più risposte (1)
Orion
il 10 Nov 2014
0 voti
Hi,
a lot of classical matlab functions are NOT supported by the "Matlab function" block (in the preivous version, it was "Embedded Matlab function")
you could instead use the "interpreted Matlab function" block, which call an external script .m (difference with the matlab function, which is a simulink block, so the code inside is interpreted by simulink not matlab).
BUT, it's not obvious, because all your Mcode will be executed at each time step. so you can encapsulate your Interpreted Matlab function in a enabled subsystem which is activate only at t==0, and then the output will be constant.
it will work but it's not really pretty. also, you can't generate C code with an interpreted function in a model.
Note : if your M-code calculate just a matrix independant of the time, why don't you load it in your model with a Constant block ?
1 Commento
Antoine
il 10 Nov 2014
Categorie
Scopri di più su Data Types in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!