0

I have a main matlab file. The main file accesses several functions. There is a loop in one of the functions and I want to see each part of the loop even though those variables aren't being stored. I am new to matlab and I don't understand whether the inputs are matrices, vectors or elements. How do I do that?

matrix1 = [1 2 3 4; 4 5 6 5; 7 8 1 0;3 5 7 6]
list1 = [1;3;5;4]
i=0
for a=1:1:4  %no. of rows
    for b=2:1:4 % no. of col
        x=matrix1(a,b);
        s=1
        n3=list1(a,1); %vector
        mult=(s.*sin(i)./n3);
    end
end

This is a part of a function that the main file calls. x, n3, mult are all being used but none of them are being saved. How can I see what these values are?

  • 1
    It's rather unclear what your problem is. You already have several mentions as `matrix, %vector` etc in your code. Can you please post a [mcve], i.e. code that is representative of your problem and that we can run, and point out which variables you want to extract? – Adriaan May 06 '20 at 12:45
  • Does that help? The code is too large and there are too many elements involved. I tried to show a minimal example. I hope this helps. – jazzytortoise May 06 '20 at 12:55
  • 2
    if you want to inspect code, debugging is the best tool. Put a breakpoint and run the code only until that point. Removing `;` will also print the variables (e.g. in your exmaple you should see `matrix1` `list1` and `i` being printed. You can also use `disp()` – Ander Biguri May 06 '20 at 12:57
  • Is there any way I can see x, n3 and mult as they are updated in the loop? This is in a function written seperately from the main file so it cannot be run by itself. – jazzytortoise May 06 '20 at 13:02
  • Yes, as @AnderBiguri suggested, you put a beakpoint in the function which will pause execution when it gets to that point. From there you can see the variable values, and then step through the code or continue to the next time that function is called. See https://www.mathworks.com/help/matlab/matlab_prog/set-breakpoints.html – beaker May 06 '20 at 14:46

0 Answers0