i have to run .m file 51 times. how can i save all 51 results in one file?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Muhammad Umer
am 7 Sep. 2015
Kommentiert: Walter Roberson
am 9 Sep. 2015
The program contains 3 functions:
function algorithm code,
function bounds,
function problem code,
In result it creates a .mat file with 1 value. i have tried several options to do multiple runs with multiple outputs in 1 file like on every run it adds new value in file but it couldn't works .
Is there any way to solve this thing?
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 7 Sep. 2015
Bearbeitet: Walter Roberson
am 7 Sep. 2015
function f = multilop() %store this in multiop.m
for k=1:51,
algresult(k,:) = algorithmcode();
boundsresult(k,:) = bounds();
problemresult(k,:) = problem();
end
end
%this part can be in algorithmcode.m or in multiop.m
function aresult = algorithmcode()
aresult = .... whatever appropriate
end
%this part can be in bounds.m or in multiop.m
function bresult = bounds()
bresult = ... whatever appropriate
end
%this part can be in problem.m or in multiop.m
function presult = problem()
presult = ... whatever appropriate
end
4 Kommentare
Walter Roberson
am 9 Sep. 2015
Take your code for "function algorithm code" and write it in a file named algorithmcode.m . Take your code for "function bounds" and write it in a file named "bounds.m". Take your code for "function problem code" and write it in a file named "problemcode.m".
In each case, the name of the file must exactly match the name of the function on the "function" line, which must be the first line of the file that is not blank or a comment.
In each case, the function name must start with a Latin Alphabet letter, A through Z or a through z. The remaining characters of the function name must be one of those Latin Alphabet letters, or one of the digits 0 through 9, or the underscore character '_' . It is not permitted to have blanks in the name of the function.
function 2do %not allowed! name must start with letter
function problem code %not allowed! name must not have spaces
function problemcode %allowed
Weitere Antworten (1)
Geoff Hayes
am 7 Sep. 2015
Muhammad - try saving the results of each iteration to an array and then, once the last iteration has completed, write this array to the mat file.
4 Kommentare
Geoff Hayes
am 7 Sep. 2015
Bearbeitet: Geoff Hayes
am 7 Sep. 2015
Muhammad - typically, the error
Maximum recursion limit of 500 reached.Use set(0,'RecursionLimit',N) to change the limit. Be aware that exceeding your available stack space can crash MATLAB and/or your computer.
indicates that a function is calling itself recursively (without a "stopping" condition). For example, the following code would generate the same error
function algorithm
algorithm
If the above is saved to a file called algorithm.m and then called from the command line, then we would observe the same error that you have described. Have you perhaps done something similar in your algorithm function?
As for the second error
Function definitions are not permitted in this context.
this generally happens if you write a function signature after you have already written some code within your script. For example, if the following is saved to a file called myScript.m
% some dummy code
t = 42;
function myFunction(a,b,c)
and then I try to execute the script, I would see the same error as you. Have you written something similar in your code?
Please post some or all of your code so that we can get an idea of what you have written and what can be done so that you can obtain the results that you desire.
Siehe auch
Kategorien
Mehr zu Environment and Settings 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!