Question on CATEGORICAL and Help files
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Georges
le 20 Août 2014
Commenté : Peter Perkins
le 22 Août 2014
Well, not a question as much as a comment. I'm finding the Help files a bit too brief for this class. Does any one else agree?
For example:
- How to preallocate a categorical array? I'm dealing with 13,000,000 records and moving the data into variables in 32 bit machine hits the memory limit quickly. Preallocation is critical inthis application.
- How to turn a categorical array back into numbers of characters? Hehe, trying to use the variable editor and paste the categorical data into a column of another (non categorical) variable, froze the machine (or was it a crash?).
0 commentaires
Réponse acceptée
Sean de Wolski
le 20 Août 2014
I usually preallocate tables or categoricals dynamically by running my loop backward
T = table;
for ii = 10:-1:1;
T(ii,:) = array2table(rand(1,4));
end
To your second question:
c = categorical({'red';'red';'blue'})
cellstr(c)
9 commentaires
dpb
le 21 Août 2014
Both...I'm not at all enamored of the idea of changing the UI, either...I use very little of it other than keyboard, anyway.
Peter Perkins
le 22 Août 2014
In addition to what Sean said about preallocating the memory using a backwards loop
- you can also assign any value to the last element and then run the loop in the usual direction, and
- it will be a performance gain to also preallocate the categories if you know them in advance.
So
c(1000,1) = categorical('',{'abc' 'def' 'ghi'});
Presto, a 1000x1 categorical array. You could of course also do this
c = categorical(repmat({''},1000,1),{'abc' 'def' 'ghi'});
but there's no real reason to.
Plus de réponses (1)
dpb
le 20 Août 2014
a) Can't -- nominal or ordinal create the categorical array from an existing array--no other method is provided.
b) double and various intXX are numeric conversions; cellstr or char for character data
See
doc categorical
for details.
If data are character, you may in the end save memory with such manipulations as
x=nominal(x);
if x is a character variable but you'll have to have the original x initially. If you're running into memory problems loading the data to begin with, about all you can do that I can think of is to load it piecemeal, convert to categorical with a (hopefully sizable) savings in memory that then allows you to load some more.
Or, of course, find a way to process the data other than "all in one swell foop"
0 commentaires
Voir également
Catégories
En savoir plus sur Categorical Arrays dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!