How can I pick out two values of cell array with NaN without using a forloop and using indexing instead?
    2 views (last 30 days)
  
       Show older comments
    
Hi there. I have a cell with these properties:
 whos all
  Name           Size               Bytes  Class    Attributes
all       226051x1             32616672  cell
>> all{1,1}
ans =
    60    48    62    32
I want the second and third element, such as all{1,1}(1,2:3)=[48 62]
So far I have done it in a forloop, like so:
Flag_DO=NDBCdata.F_DO_mgl;
rawDO=NDBCdata.DO_mgl;
fh1 =@(x)any(isnan(x(:)));
whereNaN_Flag_DO=cellfun(fh1, Flag_DO); 
whereNaN_DO=cellfun(fh1, raw_DO);
mat1=cell2mat(whereNaN_Flag_DO);
mat2=cell2mat(whereNaN_DO);
itrs=size(Flag_DO);
itrs=max(itrs);
Store1=zeros(itrs,2);
ErrNum=cellfun(@double, Flag_DO, 'UniformOutput', false);
for gg=1:itrs
    if mat1(gg) ==0 | mat2(gg) ==0
        Num=ErrNum{gg,1}(1,2:3);
        Store1(gg,:)=Num;
    end
end
meaning=char(Store1);
I also noticed that the if statement isn't being used because the output is the same number of elements as the input, and there is definitely NaN's in the input.
0 Comments
Answers (1)
  Matthew Eicholtz
      
 on 27 Jun 2013
        If I understand you correctly, the following code should work:
a = {1:4;[5 nan 6 nan];[8 9 nan 10];[11 nan nan 12];13:16}; % arbitrary data
b = cell2mat(cellfun(@(c) c(2:3),a,'uni',0)); % resulting matrix
In this case, the variable a is what you are calling all (I don't suggest using variable names that are also built-in MATLAB functions), and b is what you are calling Store1.
0 Comments
See Also
Categories
				Find more on Logical in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
