Find special conditions in a cell array with struct format MATLAB -
Find special conditions in a cell array with struct format MATLAB -
this question.
i have next variables:
a={'bb.ai';'jl.ai';'bb.aa';'hh.jj.bb';'jl.h1.p6';'h1.p2'}; b={'bb';'bb.jj';'jl.h1.p6'}; now want function uses input info b in a, , next information:
[result]=somefunction(a,b) and variable result struct:
result(1).label={'bb'}; % first value of cell array b. result(1).f1={'bb.ai';'bb.aa';'hh.jj.bb'}; % these values of cell array have 'bb'; result(1).f2=[1;3;4]; % these positions in value 'bb'; result(2).label={'bb.jj'}; % sec value of cell array b. result(2).f1={'hh.jj.bb'}; % values of cell array have 'bb.jj'; result(2).f2=[4]; % these position in value 'bb.jj'; result(3).label={'jl.h1.p6'}; % 3rd value of cell array b. result(3).f1={'jl.h1.p6'}; % values of cell array have 'jl.h1.p6'; result(3).f2=[5]; % position in value 'jl.h1.p6'; result(4).noneused={'jl.ai','h1.p2'}; % these values weren't used. result(4).f2=[2;6]; % these positions in values non used; i tried this, had utilize lot of loops, hope can create easer, maybe cellfuns, thanks!
[result]=somefunction(a,b) h2=[]; i=1:size(b,1) [a] = strread(b{i}, '%s', 'delimiter','.'); h=cell(size(a,1),1); k=1:size(a,1) h{k,1} = cell2mat(cellfun(@isempty,(strfind(a,a{k})),'uniformoutput', false))==0; end h=cell2mat(h'); if size(h,2)>1 h=sum(h')'; end h=find(h==size(a,1)); if ~isempty(h) result(i).label=b{i}; result(i).f1=a(h); result(i).f2=h; end h2=[h2,h']; clearvars h end a2=a;a3=1:size(a,1); a3(unique(h2))=[]; a2(unique(h2))=[]; result(i+1).label=a2; result(i+1).f1=a3;
matlab struct cell
Comments
Post a Comment