SDG
SDG

Reputation: 2342

None of my MATLAB variables from my function are appearing in my workspace? I don't want them to be output variables

enter image description here

Why aren't any of the varibles from filter_img appearing in my workspace? This would be very helpful to my debugging.

I also need to clarify the fact that these variables used to appear on my workspace without them being outputs.

Upvotes: 0

Views: 2846

Answers (4)

Zoltan Csati
Zoltan Csati

Reputation: 699

If you want to see them on your workspace, use a script instead of a function or return all the necessary parameters as function outputs. See base and function workspaces. There are other ways for sharing variables between workspaces, like persistent variables, global variables or might look for the evalin command.

Upvotes: 2

A I
A I

Reputation: 381

If I understood your question correctly:

In order for you to see variables of a function in Matlab you have to run the code with a breakpoint set after the variable you want to see.

If you just run it like this it will just run through (or crash) without the variables being saved in the workspace.

It looks to me with

->> filter_img

->>

sign that you have run it but without any breakpoints. They are red next to the line numbers in the editor window.

I hope this helps.

Upvotes: 1

nivag
nivag

Reputation: 573

In a matlab function all variables created in that function are local to it and unless they are an output are deleted when the function finishes.

To see the variables either make your function a script, by deleting the function line or add a breakpoint somewhere in your function (by clicking next to the line number before running.

Generally, for this reason having a function with no inputs or outputs in matlab is a bit pointless so you should probably change that anyway.

Upvotes: 1

houtanb
houtanb

Reputation: 4100

They're in a function so they're only in your workspace while the function is executing. Once it is done, they will no longer be in your workspace.

To see them, you can type keyboard somewhere in the function and then use the matlab debugger to step through your function, checking the values of the variables in the command window.

Upvotes: 1

Related Questions