MATLAB merging the codes
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello, I have a question about choosing the cases in MATLAB. I have four different calculations and equations. They all start with the same set of variables. There is a couple of different equations and after those parts, they all continue with the same lines of codes after that point. All I need is that;
a=... b=... c=...
[....... ........ DIFFERENT EQNS FOR FOUR DIFFERENT CASES]
[SAME LINES AFTER THAT]
I have four different .m files at the moment. I want to merge them into one.
Thanks in advance!
Regards.
1 Kommentar
James Tursa
am 7 Nov. 2016
Bearbeitet: James Tursa
am 7 Nov. 2016
How do you determine which case to run? Is there a variable you use for switching between them? Is this determined from the inputs (a,b,c,...) themselves?
Antworten (2)
Ali
am 7 Nov. 2016
1 Kommentar
James Tursa
am 7 Nov. 2016
I still don't understand. Are you asking how to do something like this?
a=... b=... c=...
CASE 1 code
SAME PARTS
CASE 2 code
SAME PARTS
CASE 3 code
SAME PARTS
CASE 4 code
SAME PARTS
without copying all of the SAME PARTS code? Or what?
Ali
am 7 Nov. 2016
1 Kommentar
James Tursa
am 7 Nov. 2016
Without seeing your code, all I can offer is that you put the SAME PARTS code in a function and call it with your various inputs, putting the results into different variables (or maybe different parts of a cell array or struct).
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!