how is it possible to remove all the cells??
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
samicorp
am 1 Mai 2017
Kommentiert: Image Analyst
am 2 Mai 2017
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 Kommentare
Rik
am 1 Mai 2017
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));?
Akzeptierte Antwort
Image Analyst
am 1 Mai 2017
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 Kommentare
Image Analyst
am 2 Mai 2017
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
Weitere Antworten (1)
Jan
am 2 Mai 2017
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.
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!