how to process cell array
    6 次查看(过去 30 天)
  
       显示 更早的评论
    
Hi guys
I have two cell arrays A, B.
A = {[1 -1 1], [2 3 6 5]};
B = {[2 1], [1 4]};
B is the index for A.
I'd like to have a certain function A(B) give me
C = {[-1 1], [2 5]}.
Aside from cellfun, Is there any other ways to do this?
Thanks,
2 个评论
回答(1 个)
  Honglei Chen
    
      
 2012-8-6
        
      编辑:Honglei Chen
    
      
 2012-8-6
  
      c = cellfun(@(a,b) a(b),A,B,'UniformOutput',false)
or
c = arrayfun(@(x)A{x}(B{x}),1:length(A),'UniformOutput',false)
2 个评论
  Honglei Chen
    
      
 2012-8-6
				
      编辑:Honglei Chen
    
      
 2012-8-6
  
			Added a solution with arrayfun, but I don't know if arrayfun is ok
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



