Separate part of function's codes as script?

I have a question, is it possible to separate the part of a function into a separate script, which still can get access to inputs of original function and give values back to caller function?
/-------------------------------/
<File 1: f.m>
function f()
input = 1;
....
% Call the script
script.m
....
output = output + 1;
/-------------------------------/
/-------------------------------/
<File 2: script.m>
output = input + 1;
/-------------------------------/

 채택된 답변

Stephen23
Stephen23 2015년 2월 16일
편집: Stephen23 2015년 2월 16일

0 개 추천

Why don't you try it and find out?
Or you could read MATLAB's very helpful documentation on workspaces : When you call a script from a function, the script uses the function workspace.
This means a script can use any variables already existing in the function's workspace, and any variables it creates or alters will remain in that function's workspace. But actually I would recommend that you call another function, rather than a script (unless you have a good reason to do so). You could make this a local function too.
There are lots of other useful things to know about scripts and functions, and explanations of their main differences .

댓글 수: 1

Song
Song 2015년 2월 16일
I found out the solution by myself. Anyway thanks.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Simulink Functions에 대해 자세히 알아보기

질문:

2015년 2월 16일

편집:

2015년 2월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by