How to connect six scripts of matlab??
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Giuseppe
am 19 Mai 2014
Kommentiert: Henric Rydén
am 19 Mai 2014
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.
0 Kommentare
Akzeptierte Antwort
Henric Rydén
am 19 Mai 2014
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 Kommentare
Henric Rydén
am 19 Mai 2014
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.
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!