Does Simulink and Matlab has different compiler for user defined functions?
Ältere Kommentare anzeigen
I wrote a function in Matlab and it works just fine. When I put it in the Simulink User defined block Matlab fcn it does not work. Simulin returns error on array mismatch.
function G = my_fcn(X)
nule = zerocros(X);
k = size(nule);
n = 1;
i = 0;
G = [];
for i=1:k(1,1)
if i + 10 > k(1,1)
break
end
Y = nule(i:i+10);
if Y(11) > 10
G(:,n) = Y - Y(1);
G(:,n) = G(:,n)./G(11,n);
G(1,n) = nule(i);
G(11,n) = Y(11);
n = n + 1;
end
end
Simulink returns:
Index exceeds matrix dimensions. The array G is empty and therefore has no valid indices. Error in 'za_simulink_zerocross/MATLAB Function' (line 13) G(:,n) = Y - Y(1);
("Y" is one dimensional array and its size is always 11.)
Matlab returns nothing and function works. 1. What is the difference in Matlab vs Simulink fcn? 2. How to define some kind of flexible array that can increment number of columns.
Best
Akzeptierte Antwort
Weitere Antworten (1)
Zeljko Tomicevic
am 12 Jan. 2018
0 Stimmen
1 Kommentar
Birdman
am 12 Jan. 2018
It depends on how you look at things. On the other hand, Simulink offers so much different toolboxes ready to be used. On MATLAB, you need to write the code to say the least. But anyway, do your thing how you find easy.
Kategorien
Mehr zu Simulink Coder finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!