How to connect six scripts of matlab??

조회 수: 2 (최근 30일)
Giuseppe
Giuseppe 2014년 5월 19일
댓글: Henric Rydén 2014년 5월 19일
Hello,I have the following problem: I have written six scripts matlab. In the first script, the user must enter the variable n_strati (a number between 1 and 5). The first script allows you to make choices about computing models based on variables known or unknown , and runs them to n_strato=1. The second third fourth and fifth script follow the same procedure , respectively, for the layers 2-3-4-5, but in which the input parameters (not intended as a value) are different. For example :
for Strato1 performs calculations knowing the input variables A B E (and not C D F) , for Strato2 performs calculations knowing A C E (and not B D F) , for Strato3 knowing the variables B D F (and not A C E).
The sixth takes all the variables of the previous scripts and processes them to obtain the final result. The first five scripts save the data using the command:
save Strato1 alpha beta gamma etc.
and the sixth script them "stores" with the command:
load Strato1 load Strato2 etc.
But I have to make sure that:
if n_strati==1 I enter the data and choose the models in script1 jumping scripts 2-3-4-5 and proceeding with the final calculation through the script 6 .
if n_strati==2 I enter the data and choose the models for Strato1 in script1 and Strato2 in script2 jumping scripts 3-4-5 and proceeding with the final calculation through the script 6 . and so on.
I wanted to know: how can I do?
Thank you for your cooperation.

채택된 답변

Henric Rydén
Henric Rydén 2014년 5월 19일
I would suggest you turn your scripts into functions and create a script that calls the functions.
If that's not possible, you can use global variables but you should avoid them if you can as they are difficult to debug.
  댓글 수: 2
Giuseppe
Giuseppe 2014년 5월 19일
Great idea! Unfortunately I'm not an expert ... so could you kindly explain to me how I can turn a script into a function?, And how do I call the function that I create in the script that should contain everything? Thank you.
Henric Rydén
Henric Rydén 2014년 5월 19일
Hi!
A function is defined like this
function sum = addTheseNumbers(x,y)
sum = x + y;
end
Which you store in an addTheseNumbers.m-file. Now you can call the function using
z = addTheseNumbers(4,5);
You need to look at your scripts and figure out what you input and output is necessary for each of them, and create functions instead. As I don't know the problem your solving, it's difficult to give better advice.
It's usually a good thing to make functions only do one specific thing so that you can reuse them later in a different project.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by