Script to function help

조회 수: 1 (최근 30일)
Gilmar
Gilmar 2013년 10월 15일
댓글: Azzi Abdelmalek 2013년 10월 17일
So I have a script that uses simulink, and it calls upon stuff saved in workspace, but I now need to change the script into a function that gives me 4 outputs and accepts 20 inputs. I have something like this set up:
function[a,b,c,d] = myfunc(x1,x2,x3,...x20)
but the problem I'm getting is that the simulink is not getting any values being saved. I think it has to do with functions not saving to the normal workspace. What I'm trying to find out is how I can just make my whole function save its variables into workspace?

답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 10월 15일
  댓글 수: 6
Gilmar
Gilmar 2013년 10월 17일
편집: Gilmar 2013년 10월 17일
No, I have this one pretty long script. When I run the script the first 1/4th of the script sets the initial values of some variables that are supposed to be user-inputted, but is hard-coded since it's a script. Currently the script takes those initial variables saves them in workspace like most scripts do, and the script continues to run, while the script is running there's a line in the script that calls a specific simulink module already created, and that simulink module gets the values from the script, then after the simulink module is done running it returns that information to the same script, where the script continues to do some equations using the information obtained from the simulink module. I run into a problem when I try to change the hard-coded information into a function with user inputs, because I need it to accept user information and not have it always be hard-coded in the script.
So when I try running it as a function the line that calls upon my simulink module is not getting the values like it used to. and I think the reason why is because the simulink module just looked into workspace for those values, but since it is a function that information does not get saved to workspace anymore.
So I don't know if I can tell the simulink module to look for that information somewhere else, or if I can just set all my variables as global so simulink can get it?
Also sorry if this still doesn't make that much sense.
Azzi Abdelmalek
Azzi Abdelmalek 2013년 10월 17일
편집: Azzi Abdelmalek 2013년 10월 17일
Just use the variables needed by simulink model v1,v2,...as output argument in your function
[var1,var2,...]=you_function(x1,...)

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

카테고리

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