Matlab can not evaluate the maximum of an array?

조회 수: 2 (최근 30일)
Alessandro Longo
Alessandro Longo 2017년 11월 8일
답변: Steven Lord 2017년 11월 8일
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
Birdman
Birdman 2017년 11월 8일
I can't open it with r2017a, please export it to r2017a.
Alessandro Longo
Alessandro Longo 2017년 11월 8일
편집: Alessandro Longo 2017년 11월 8일
Try this link, I can not update slx files Download

댓글을 달려면 로그인하십시오.

답변 (2개)

Rik
Rik 2017년 11월 8일
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
Alessandro Longo
Alessandro Longo 2017년 11월 8일
I tried to paste your code but Simulink tells me there is an error in the if block (Illegal use of if)

댓글을 달려면 로그인하십시오.


Steven Lord
Steven Lord 2017년 11월 8일
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.

카테고리

Help CenterFile Exchange에서 Sources에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by