필터 지우기
필터 지우기

converting matrix to constant value in matlab function (Simulink)

조회 수: 4 (최근 30일)
AN
AN 2020년 12월 7일
댓글: Jon 2020년 12월 7일
Hello everyone,
I'm writing a MATLAB-Function in Simulink and I am trying to create an output constant of an input matrix that is supposed to contain the minimum index-value of the matrix-values that are above a certain value. My function is:
function y =fcn(s,m)
z=s>m;
w=find(z);
y=min(w);
Now when I run this, simulink gives me the error "The signal at 'Input Port 1' of 'File/Scope1' is a variable-size signal with a nondiscrete sample time. The sample time for any variable-size signal must be discrete."
I just want the variable y to have a scope as output. What do I do? I tried changing the properties of y to non-variable, but then it says "If the working dimension of MAX or MIN is variable in length, it must not have zero length at runtime."

채택된 답변

Jon
Jon 2020년 12월 7일
Try a MATLAB Function block with the following, this worked for me
function y = fcn(u,m)
y = min(u(u>m));
  댓글 수: 4
AN
AN 2020년 12월 7일
Thank you so much for your fast reply! It really helped me out to know that the idea was right.
So I had to adjust the code a little bit because other blocks in the model were interfering. In case anyone ever has a similar problem: an if-function might do the trick. :)
if z==0
y=0;
else
w=find(z);
y=min(w);
end
Jon
Jon 2020년 12월 7일
Glad to hear you got it going. The edge cases always get you :)

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by