From: jenya polyakova on 25 Feb 2010 18:55 Let say I have two logicals: r1 = [0 1 1] and r2 where r2{1} =[0 0 0 0] r2{2}=[1 1] r2{3}=[1 0 0 0 0 1] Let's say I have cell array a where a{1}=1:4; a{2}=[10,5]; a{3}=[9,1:4,8]; I would like now to use r1 and r2 to do extract elements from a where r1 and r2 are non_zero. so I would have b = [ 10 5 9 8] Of course I could loop to find non-zero elements....just looking for nicer solution as my real data is HUGE. Thanks.
From: Wayne King on 25 Feb 2010 19:38 "jenya polyakova" <jenya56(a)yahoo.com> wrote in message <hm72l8$m0r$1(a)fred.mathworks.com>... > Let say I have two logicals: > > r1 = [0 1 1] > > and r2 where > r2{1} =[0 0 0 0] > r2{2}=[1 1] > r2{3}=[1 0 0 0 0 1] > > Let's say I have cell array a where > a{1}=1:4; > a{2}=[10,5]; > a{3}=[9,1:4,8]; > > I would like now to use r1 and r2 to do extract elements from a where r1 and r2 are non_zero. > so I would have > b = [ 10 5 9 8] > > Of course I could loop to find non-zero elements....just looking for nicer solution as my real data is HUGE. > Thanks. Hi Jenya, one thing you can do is to use cellfun, but then I'm still using a loop to extract the elements from a: Indices = cellfun(@(x) find(x==1), r2,'UniformOutput',false); for k=1:size(Indices,2) a{k}=a{k}(Indices{k}); end Num = cell2mat(a); Wayne
|
Pages: 1 Prev: Transfer function matrix using symbolic math toolbox Next: colorbar question |