Difference between clear var and clear var*
3 次查看(过去 30 天)
显示 更早的评论
Hi all,
This will probably be a very straightforward question but I can't get to the bottom of it. I just started reading Mike Cohen's book 'MATLAB for Brain and Cognitive Scientists' this afternoon. He suggests checking the difference between 'clear a' and clear a*' in one of the preliminary chapters. They don't appear to do anything different. I have read the MATLAB documentation for 'clear' again (not to much to chew on), and I can't see anything.
Given what little I know about pointers from C++, I initially imagined that clear a* would remove the value stored in a from the workspace, but that the memory allocated to it would remain (just empty); and that clear a would remove variable a from the workspace entirely. I then checked both with 'whos' and both commands simply remove the variable and its value.
I downloaded a set of tip scripts from Mike's website for the book. The tip for that part of the chapter is simply:
%% 6
clear a
clear a*
In a last-ditch effort, I Googled it in a few different ways, but turned up nothing.
There are a thousand more interesting issues and questions I could ask, but this is just driving me up the wall because I can't find the answer, even though I know it will be simple. Does anybody know what exactly he is trying to get at with this?
Cheers!
Rowan.
0 个评论
采纳的回答
Steven Lord
2019-8-31
Let's start with a blank workspace.
>> clear all
Create three variables and check that they all exist in the workspace.
>> a = 1;
>> ab = 2;
>> abc = 3;
>> whos
Name Size Bytes Class Attributes
a 1x1 8 double
ab 1x1 8 double
abc 1x1 8 double
Run the first command. What's in the workspace now?
>> clear a
>> whos
Name Size Bytes Class Attributes
ab 1x1 8 double
abc 1x1 8 double
Run the second command. What's in the workspace now?
>> clear a*
>> whos
>>
If you're not certain exactly what a particular command does, I recommend checking its help text and/or its documentation. In this case, the help text describes how "clear a*" is interpreted.
>> help clear
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!