Matlab can not evaluate the maximum of an array?
Afficher commentaires plus anciens
Hello, I am trying this simple Simulink diagram:

and I would calculate the maximum of the function (that is 1). As you can see, it does not work. Just for completion, this is the Matlab function code:
function y = fcn(u)
y = max(u);
Why?
4 commentaires
Birdman
le 8 Nov 2017
Can you send your simulink model?(export to r2017a)
Alessandro Longo
le 8 Nov 2017
Birdman
le 8 Nov 2017
I can't open it with r2017a, please export it to r2017a.
Alessandro Longo
le 8 Nov 2017
Modifié(e) : Alessandro Longo
le 8 Nov 2017
Réponses (2)
Rik
le 8 Nov 2017
I have hardly ever worked with Simulink, so I might be wrong, but I would think the function gets executed every time step (which would explain the almost 0 value). So you will have to define a persistent variable in your function to save the previous maximum.
function y=fcn(u)
persistent OldMaximum
if isempty(OldMaximum),OldMaximum=-if;end
OldMaximum=max([OldMaximum u]);
y=OldMaximum;%persistent variables can't be used as an output
1 commentaire
Alessandro Longo
le 8 Nov 2017
Steven Lord
le 8 Nov 2017
0 votes
What is the maximum of your signal at time t = 2? Since your signal is a scalar the maximum of a scalar is the scalar itself. Since it sounds like you want the maximum over time not the maximum over the elements in your signal use the MinMax Running Resettable block instead of the MATLAB Function block or the MinMax block.
Catégories
En savoir plus sur Simulink dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!