MATLAB: Doesnt the workspace show the variables

variableworkspace

I run the programme, it ends without any problem. Also with whos command i can see the variables in command window. But workspace doesnt show anything, Also after finishing the run process, i write the variable to the command window but it says undefined variable. Do you know what is the problem? I need to see the variables content from workspace.

Best Answer

Function programs often run through dozens, if not hundreds, of variables before reaching a desired output as designated by the writer. Check the text of the code to determine if the variables you are looking for are output variables. Below is an arbitrary example:
[value1 value2] = function(x)
internalVariable = x * cos(x+10);
value1 = sin(internalVariable)
value2 = tan(internalVariable)
In this code, value1 and value2 are output and will be moved to the workspace. The internalVariable will not be placed in the workplace because it is not designed to be part of the function output. If you would like to make sure the variables are being output into the workspace change the function line to look like this:
[value1 value2 internalVariable] = function(x)
Then when you run the function with three output requests, you will obtain the desired variable in the workplace.
The other way to obtain all the internal variables without editing the code is to run the function within the cell mode in the editor using Ctrl+Enter. This will put all of the internal variables into the workspace.
Hope this helped!