pausing for loop after every iteration and display the results MATLAB

538 views Asked by At

I have the following code where I call a function in a loop and pause it after every iteration:

[num,txt1,~]=xlsread('test.xlsx',1);
for i=2:5
    [num,txt2,~]=xlsread('test.xlsx',i);
    for j=1:3
        txt_input=txt2(2:end,j);
        neurPep=neuroPred(txt1,txt_input);
       pause
    end
   pause
end 

I expected the Workspace would show up the values of the computed variables everytime I pause the loop, but only the values corresponding to the very last iteration are being shown towards the end.

What changes do I need to make such that values are updated after every loop and shown in the Workspace?

1

There are 1 answers

0
Matt On BEST ANSWER

The pause command only suspends Matlab execution. Since the normal flow of Matlab execution is not to update the workspace, pausing doesn't do what you want in this instance. The keyboard command takes Matlab into debug mode. This mode will update the workspace with your current values. You can continue execution by typing dbcont into the command line.

Another option is to open the .m file in the Editor and click on the "-" next to the line number on the left of the line. This will also enter debug mode. In that case hit F5, type dbcont or press the play button to continue execution.

The takeaway here is: Debug mode is your friend.

Here are the references: pause keyboard