I have a matlab function file which contains the main function which calls on many subfunctions. I would like to look at the output of the subfunctions in my program. How do I do this?
As it is now I have been making separate scripts to see what the output is of each of the individual subfunctions, I do not want to have to do it this way anymore.

 Réponse acceptée

Adam
Adam le 19 Août 2014

0 votes

If you just want to have a look at them then put breakpoints in the file containing your main function and you can see the intermediate outputs in your function's workspace.
If you want the intermediate outputs to persist then just add them as output arguments of your main function.

3 commentaires

richard
richard le 19 Août 2014
OK this has seemed to be the easiest to implement, however I have a FOR loop in my main function. How can I see the value of something in the loop at a particular iteration?
Iain
Iain le 19 Août 2014
This is a way of doing it.
if iteration_number == desired_value
keyboard % this lets you do stuff other than just see a value
disp(value_of_interest) %this just prints it to screen
end
Adam
Adam le 19 Août 2014
Put a conditional breakpoint in based on the for loop control. If you add a breakpoint and right-click you get the option to 'Set / Modify condition'. In there you can put, for example:
i >= 15
if you have a for loop like:
for i = 1:100
...
end
In that example then your breakpoint will first hit at i == 15 and then if you press F5 it will hit again every iteration until the end. If you just want it to hit once then make your condition something like i == 15;

Connectez-vous pour commenter.

Plus de réponses (2)

John D'Errico
John D'Errico le 19 Août 2014

0 votes

From your main function, return function handles for each subfunction. Then you can use them as independent functions.
Image Analyst
Image Analyst le 19 Août 2014
You can make one m-file for them all. For example in test.m, you can have test(), sub1() and sub2() all in one single file:
function test()
out1 = sub1(10)
out2 = sub2(20)
function out = sub1(in)
fprintf('in = %f', in); % Or whatever you want to do.
function out = sub2(in)
fprintf('in = %f', in); % Or whatever you want to do.

Catégories

En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange

Question posée :

le 19 Août 2014

Commenté :

le 19 Août 2014

Community Treasure Hunt

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

Start Hunting!

Translated by