How to find maximum value of function and return x in simulink

I have a problem with finding maximum value of function which I got on output.My function is very similar to simple sinus and I need to find maximum value of it and for this value return x as a new output. I can only use simulink for this problem, without matlab function or S-function.
Anyone can help?

2 Comments

Can you explain if you want the maximum value at the end or during simulation?
I have sinus type function and I need to find point where this funcion reach maximum value and return index of this point. It should happen during simulation and find only first maximum.

Sign in to comment.

Answers (2)

You can calculate (using unit delay or memory and sum block) out(n)-out(n-1), when it becomes negative, it's your first maximum
You can use Matlab function block with the code:
function y = fcn(u)
%#codegen
persistent k up test
if isempty(k)
k=0
up=0;
test=0;
end
e=u-up
if or(e<0,test==1)
y=k
test=1;
else
k=k+1
y=0
up=u
end

Categories

Products

Tags

Asked:

on 15 Jan 2013

Community Treasure Hunt

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

Start Hunting!