how is it possible to remove all the cells??
1 次查看(过去 30 天)
显示 更早的评论
is there a way to clear all the cell arrays at the beginning of the code like the way we do it for variables with clear all? if it is possible i do not want to clear each cell one by one like a{:} = {[]}; is there a way to remove all at once ? regards
3 个评论
Rik
2017-5-1
First off, never use clear all, use clear variables instead.
Now to your question. Is there a reason you can't just overwrite your variable with something like C=cell(size(C));?
采纳的回答
Image Analyst
2017-5-1
Use the command
varInfo = whos
by examining the varinfo structure, you can determine which variables are cell arrays. For example, when I called it when I had 11 variables in existence:
varInfo =
11×1 struct array with fields:
name
size
bytes
class
global
sparse
complex
nesting
persistent
Loop over all elements in the structure array and if you find a cell array, initialize it.
for k = 1 : length(varInfo)
if strcmpi(varInfo(k).class, 'cell')
% It's a cell array - initialize it
end
end
Frankly, it might be less complicated just to assign the known names of cell arrays to something. I mean, you know the names in your program, don't you?
2 个评论
Image Analyst
2017-5-2
I'm not sure what you're asking. I showed you how to find all the variables in your workspace that are cells or cell arrays (arrays of cells). And I show you how to loop over all of those. Or are you asking how to loop and visit every cell that is one element of a cell array?
Not sure you know what a cell is completely. See the FAQ for a discussion that should give you a good intuitive feel for what they are and how to use them. http://matlab.wikia.com/wiki/FAQ#What_is_a_cell_array.3F
更多回答(1 个)
Jan
2017-5-2
Do not use clear all, because it does not only clear variables, but removed all loaded functions from the memory also. reloading them from the slow hard disk wastes a lot of time.
Using a general method to clear variables is not clean also. Better create functions for your codes, such that the workspace is kept clean.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!