Prev: Scrollable Panel
Next: Prediction for ARMAX model
From: Adam Andersen Læssøe on 8 Feb 2010 17:10 I have a cell array in a structure sys.T : sys= T: {1x8 cell} Each cell contains a one dimensional array, e.g.: sys.T{1} ans = 1 3 13 8 7 2 I want to find the cells containing for instance 3. Based on my searching results I try: >> find(cellfun(@(x) x==3,sys.T)) ??? Error using ==> cellfun Non-scalar in Uniform output, at index 1, output 1. Set 'UniformOutput' to false. And therefore : >> find(cellfun(@(x) x==3,sys.T,'UniformOutput',false)) ??? Undefined function or method 'find' for input arguments of type 'cell'. What am I doing wrong?
From: Nathan on 8 Feb 2010 17:19 On Feb 8, 2:10 pm, "Adam Andersen Læssøe" <aala...(a)gmail.com> wrote: > I have a cell array in a structure sys.T : > sys= > T: {1x8 cell} > Each cell contains a one dimensional array, e.g.: > sys.T{1} > ans = > 1 3 13 8 7 2 > > I want to find the cells containing for instance 3. > Based on my searching results I try:>> find(cellfun(@(x) x==3,sys.T)) > > ??? Error using ==> cellfun > Non-scalar in Uniform output, at index 1, output 1. > Set 'UniformOutput' to false. > > And therefore :>> find(cellfun(@(x) x==3,sys.T,'UniformOutput',false)) > > ??? Undefined function or method 'find' for input arguments of type 'cell'. > > What am I doing wrong? As it says, find doesn't work with cell types. You'll need another cellfun (if you want to do it this way)... Here's one approach: T{1} = 1:5; T{2} = 1:2:10; T{3} = 1:3:30; T{4} = 20:-2:6; tf = ~cellfun('isempty',cellfun(@(y)find(y),cellfun(@(x) x==3,T,'UniformOutput',false)','uni',false)); %tf contains a 1 for each array in T that contains a 3 %%%%%%%%%%%%%%%%%%%%%%%%%%% tf = 1 1 0 0 T{tf} ans = 1 2 3 4 5 ans = 1 3 5 7 9 -Nathan
From: Adam Andersen Læssøe on 9 Feb 2010 01:57 > As it says, find doesn't work with cell types. You'll need another > cellfun (if you want to do it this way)... > Here's one approach: > T{1} = 1:5; > T{2} = 1:2:10; > T{3} = 1:3:30; > T{4} = 20:-2:6; > tf = ~cellfun('isempty',cellfun(@(y)find(y),cellfun(@(x) > x==3,T,'UniformOutput',false)','uni',false)); > %tf contains a 1 for each array in T that contains a 3 > %%%%%%%%%%%%%%%%%%%%%%%%%%% > tf = > 1 > 1 > 0 > 0 > T{tf} > ans = > 1 2 3 4 5 > ans = > 1 3 5 7 9 > > > -Nathan Thanks. Well, I don't necessarily want to do it that way. I'd be happy to see a simpler approach. /Adam
From: us on 9 Feb 2010 03:02 "Adam Andersen Læssøe" <aalasso(a)gmail.com> wrote in message <hkq24c$e26$1(a)fred.mathworks.com>... > I have a cell array in a structure sys.T : > sys= > T: {1x8 cell} > Each cell contains a one dimensional array, e.g.: > sys.T{1} > ans = > 1 3 13 8 7 2 > > I want to find the cells containing for instance 3. > Based on my searching results I try: > >> find(cellfun(@(x) x==3,sys.T)) > ??? Error using ==> cellfun > Non-scalar in Uniform output, at index 1, output 1. > Set 'UniformOutput' to false. > > And therefore : > >> find(cellfun(@(x) x==3,sys.T,'UniformOutput',false)) > ??? Undefined function or method 'find' for input arguments of type 'cell'. > > What am I doing wrong? one of the solutions clear c; % <- save old stuff(!)... c{1,1}=1:4; c{2,1}=[]; c{3,1}=5:7; c{4,1}=-1:3; tf=cellfun(@(x) any(x==3),c).' % tf = 1 0 0 1 us
|
Pages: 1 Prev: Scrollable Panel Next: Prediction for ARMAX model |