From: Loren Shure on 12 Apr 2010 10:33 In article <hpnuuj$q7q$1(a)fred.mathworks.com>, matlab.THIS_YEAR(a)nMINUSsimon.de says... > Dear C T! > > > I am trying to pre-allocate a cell array of strings. I can do the following: > > > > test = cell(m,1); > > for i = 1:m > > test{i} = 'test'; > > end; > > unique(test); > > > > But I thought there may be a better solution somewhere. The main thing is being able to do unique(test); > > This is much faster than the DEAL method: > test = cell(m, 1); > test(:) = {'test'}; > > Jan > I haven't looked, but I bet the test(:) = {'test'} uses a shared data copy for the string value, whereas the deal version might not. So part of the difference might be the extra real memory allocation going on. Just a guess though. -- Loren http://blogs.mathworks.com/loren http://matlabwiki.mathworks.com/MATLAB_FAQ
From: us on 12 Apr 2010 10:46 Loren Shure <loren.shure(a)mathworks.com> wrote in message <MPG.262cf95677fa13be989ada(a)news.mathworks.com>... > In article <hpnuuj$q7q$1(a)fred.mathworks.com>, > matlab.THIS_YEAR(a)nMINUSsimon.de says... > > Dear C T! > > > > > I am trying to pre-allocate a cell array of strings. I can do the following: > > > > > > test = cell(m,1); > > > for i = 1:m > > > test{i} = 'test'; > > > end; > > > unique(test); > > > > > > But I thought there may be a better solution somewhere. The main thing is being able to do unique(test); > > > > This is much faster than the DEAL method: > > test = cell(m, 1); > > test(:) = {'test'}; > > > > Jan > > > > I haven't looked, but I bet the test(:) = {'test'} uses a shared data > copy for the string value, whereas the deal version might not. So part > of the difference might be the extra real memory allocation going on. > Just a guess though. loren actually, DEAL is using a shared copy... something along this line has been discussed several times in CSSM, eg, http://www.mathworks.com/matlabcentral/newsreader/view_thread/146789#369303 urs
First
|
Prev
|
Pages: 1 2 Prev: preallocating a cell array of strings Next: Saving Matlab Plots for Webpages |