使用cellfun
。
mystruct = struct('x', 'foo', 'y', 'bar', 's', struct('text', 'Pickabo'));
mystruct1 = struct('x', 'foo1', 'y', 'bar1', 's', struct('text', 'Pickabo'));
mystruct2 = struct('x', 'foo2', 'y', 'bar2', 's', struct('text', 'Pickabo1'));
mylist = {mystruct, mystruct1, mystruct2 };
string_of_interest = 'Pickabo'; %# define your string of interest here
mylist_index_of_interest = cellfun(@(x) strcmp(x.s.text,string_of_interest), mylist); %# find the indices of the struct of interest
mylist_of_interest = mylist(mylist_index_of_interest); %# create a new list containing only the the structs of interest
來源
2010-08-11 19:45:35
YYC