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
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));?
samicorp
samicorp 2017-5-2
@Rik Wisselink that is how you preallocate the cell but my question was how can i remove them all. as @hmi amid mentioned correctly clear all or clear variable would do the job which i did not pay attention to.

请先登录,再进行评论。

采纳的回答

Image Analyst
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 个评论
samicorp
samicorp 2017-5-2
i have already done that. the best way is to assign them one by one. although your way of assigning is also interesting. another question is that since i am working with quite large number of cells what is the fastest way of looping over all these cells? any example would be highly appreciated.
Image Analyst
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
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 CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by