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);
TIA
ct
Generally there is no gain to preallocate elements of cell if you intend to replace them later (this situation likely happens when using cell). See this thread for more detailed discussion:
http://www.mathworks.com/matlabcentral/newsreader/view_thread/258931
Bruno
test = cell(m,1);
test(:) = {'test'};
This will cause each cell to share the same physical variable 'test', so not much wasted space even if m is very large. Also gets rid of the [] cells so you can use unique.
James Tursa
[test{1:m, 1}] = deal('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
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