필터 지우기
필터 지우기

can't plot using user-defined function block.

조회 수: 1 (최근 30일)
vishnu kannan
vishnu kannan 2019년 2월 21일
댓글: Fangjun Jiang 2019년 4월 1일
I have a Matlab code to plot a graph. but when I used the same code in Simulink as a user-defined function, I am getting a lot of parellel lines instead of the desired graph in the scope block. does anyone know how to fix this?
  댓글 수: 2
madhan ravi
madhan ravi 2019년 2월 21일
편집: madhan ravi 2019년 2월 21일
share your model with your user defined function
vishnu kannan
vishnu kannan 2019년 3월 29일
SIMULINK ERROR.png
The above shown figure is my problem.
the matlab code in the user-defined function is " y=sin(x) ". but i get this plot instead of a sin wave. i have attached the code. this error is equivalent to the original error i am facing in my project.
i added an input in user-defined-function (u). but i am not using it. no input is needed from simulink, i only want to execute the .m file in userdefined function and display the output in the scope.
is there any way to correct this?

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

채택된 답변

Fangjun Jiang
Fangjun Jiang 2019년 3월 29일
편집: Fangjun Jiang 2019년 3월 29일
Keep in mind that this MATLAB Function block is executed at every simulation step you run. Your funciton ouputs 201 values at every step and these values are the same from step to step. That is why your scope shows 201 straight lines.
If you want to plot sin(x). One way to do it is to add a Simulink "Clock" block and connect its output to "u". Inside your function, simply specify it as y=sin(u).
  댓글 수: 2
vishnu kannan
vishnu kannan 2019년 3월 30일
i want to execute the matlab code inside the user-defined function and plot using scope. my original code is very complex thats why i choose the simple code y=sin(x) to demonstrate my error.
is there any other way ?
Fangjun Jiang
Fangjun Jiang 2019년 4월 1일
Just remember that in Simulink, there is a "time" element. Everything goes along the simulated "time" once you press the "Run" button.
For the sake of plotting sin(x) in Simulink without time, you could use XY scope.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Scopes and Data Logging에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by