필터 지우기
필터 지우기

How can variables in workspace be used in Simulink function

조회 수: 1 (최근 30일)
Drill Be
Drill Be 2017년 11월 6일
댓글: KL 2017년 11월 7일
Let say we have a variable defined in workspace
ax=10
I want to use this variable in a Simulink function "abc" defined as:
function y = abc(u)
y=ax*u;
end
Why simulink is showing me an error while executing this function. Alternatively, I used to declare the variable as:
global ax
but it doesn't work.
Can someone help me to solve this issue?

답변 (1개)

KL
KL 2017년 11월 6일
One idea is to take it as an input to your function block and use the "constant block".
Your function could look like,
function y = abc(ax,u)
y=ax*u;
end
Enter ax as the value in your constant block and no need to define it as global.
  댓글 수: 2
Drill Be
Drill Be 2017년 11월 6일
Dear,
Yes, you are right, but I have a huge scheme in Simulink and it is not a convenient manner. There should be a solution for such situation.
KL
KL 2017년 11월 7일
Well, If you explain more about your actual problem, it would be easier to find if there's any alternatives to global variables but anyway, using global variables inside matlab function block in simulink is explained in this documentation here.
But be warned about the dangers come with using global variables. If you have a huge scheme, it only gets worse.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by