From: Andrew Stevens on 10 Feb 2010 20:09 Hi all, I am trying to figure out a way to replace values in a cell array with NaN. I can do it with a loop, but I have somehow got myself into the CELLFUN habit and don't much like the look of the loop: %generate some data data=cellfun(@(x)(rand(x,1)),... num2cell(ceil(rand(5,1)*100)),'un',0); data = [26x1 double] [42x1 double] [34x1 double] [30x1 double] [91x1 double] %now if I want to replace values greater than 0.5 in each cell I could: for i=1:length(data) data{i}(data{i}>0.5)=NaN; end Is there a way to do it using CELLFUN? My initial attempt looked something like this: data=cellfun(@(x)(x(x>0.5)=NaN),data,'un',0); but that syntax is not valid. Any ideas? Andrew
|
Pages: 1 Prev: can't mex fortran files on mac 10.6 Next: return larger of two numbers |