Variables Not Showing in Workspace After Clearing/Workspace Won't Update Varaibles

조회 수: 41 (최근 30일)
Hello, I am pretty new to Matlab. I have an issue. I am working on some code and want to verify my outputs as I go in the workspace. Let's say I have an array of elements that I modify in 4 different lines. I would comment out certain ones, press run, and check them in the workspace, than I would uncomment other lines working on this array to check any changes, but none are showing in the workspace even though they should. How do I get them to update in workspace after making changes to a code and pressing run?
Also, I thought clearing the workspace might help with refreshing them. I thought after I clear the workspace and run my code again, the values would appear updated. Instead, no variables are showing anymore. Can anyone help?
  댓글 수: 1
Walter Roberson
Walter Roberson 2019년 9월 9일
My guess is that you have the workspace browser looking at a different workspace than you think you are looking at.

댓글을 달려면 로그인하십시오.

채택된 답변

Steven Lord
Steven Lord 2019년 9월 9일
My guess is that you're working with function files rather than script files. One of the key differences between scripts and functions is that "Functions have their own workspace, separate from the base workspace. Therefore, none of the calls to the function triarea overwrite the value of a in the base workspace."
You could call your function with output arguments. If you want to see the values of the internal variables created in the function's workspace during its execution but not returned from that function as outputs you could debug the function using breakpoints.

추가 답변 (2개)

Ted Shultz
Ted Shultz 2019년 9월 9일
You should be able to type a variable name into the command window, and have it display the value, or open a variable from workspace to inspect it. To do this, you may want to add breakpoints in your code (click to the left of the code, but the right of the line number). Then you can step throught your code.
This link has more tips for you:

Theresa Mrazkova
Theresa Mrazkova 2019년 9월 9일
Thank you everyone! It seems that my issue was working with function instead of a file script. This actually ended up happening because the code I am running was a script with a function definition, originally coded in MT2018. I am running it on a version R2016a and had to modify the file to look like functions so that it runs.

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by