tomwalters@0: % tool tomwalters@0: % tomwalters@0: % INPUT VALUES: tomwalters@0: % tomwalters@0: % RETURN VALUE: tomwalters@0: % bleeck@3: % This external file is included as part of the 'aim-mat' distribution package bleeck@3: % (c) 2011, University of Southampton bleeck@3: % Maintained by Stefan Bleeck (bleeck@gmail.com) bleeck@3: % download of current version is on the soundsoftware site: bleeck@3: % http://code.soundsoftware.ac.uk/projects/aimmat bleeck@3: % documentation and everything is on http://www.acousticscale.org bleeck@3: tomwalters@0: tomwalters@0: function lines=struct2stringarray(str,strname) tomwalters@0: % goes recursevly through the struct and appends a line for each tomwalters@0: % structthing tomwalters@0: tomwalters@0: lines=[]; tomwalters@0: tomwalters@0: counter=1; tomwalters@0: if isstruct(str) tomwalters@0: names=fieldnames(str); tomwalters@0: conts=struct2cell(str); tomwalters@0: for i=1:length(names); tomwalters@0: cstr=names{i}; tomwalters@0: tomwalters@0: nr_cont=length(str); tomwalters@0: for kkk=1:nr_cont tomwalters@0: if nr_cont==1 tomwalters@0: strstr=sprintf('%s.%s',strname,cstr); tomwalters@0: else tomwalters@0: strstr=sprintf('%s(%d).%s',strname,kkk,cstr); tomwalters@0: end tomwalters@0: % eval(sprintf('vari=str.%s;',cstr)); tomwalters@0: eval(sprintf('vari=str(%d).%s;',kkk,cstr)); tomwalters@0: tomwalters@0: newlinestr=''; tomwalters@0: if isstruct(vari) tomwalters@0: newlinestr=struct2stringarray(vari,strstr); tomwalters@0: nrlines=length(newlinestr); tomwalters@0: for j=1:nrlines tomwalters@0: lines{counter}=newlinestr{j};counter=counter+1; tomwalters@0: end tomwalters@0: else tomwalters@0: if isnumeric(vari) tomwalters@0: nrlines=size(vari,1); tomwalters@0: nrcolumns=size(vari,2); tomwalters@0: res=''; tomwalters@0: for jj=1:nrcolumns tomwalters@0: for ii=1:nrlines tomwalters@0: res=sprintf('%s %s',res,num2str(vari(ii,jj))); tomwalters@0: end tomwalters@0: if nrlines>1 && jj< nrlines tomwalters@0: res=[res ';']; tomwalters@0: end tomwalters@0: end tomwalters@0: tomwalters@0: if length(vari)>1 tomwalters@0: newlinestr=sprintf('%s=[%s]',strstr,res); tomwalters@0: else tomwalters@0: newlinestr=sprintf('%s=%s',strstr,num2str(vari)); tomwalters@0: end tomwalters@0: else tomwalters@0: if iscell(vari) tomwalters@0: res=''; tomwalters@0: for jj=1:length(vari) tomwalters@0: subvari=vari{jj}; tomwalters@0: if iscell(subvari) tomwalters@0: res2=''; tomwalters@0: for kk=1:length(subvari) tomwalters@0: res2=sprintf('%s {''%s''}',res2,subvari{kk}); tomwalters@0: end tomwalters@0: newlinestr{jj}=sprintf('%s{%d}=[%s]',strstr,jj,res2); tomwalters@0: elseif isstruct(subvari) tomwalters@0: strstrh=sprintf('%s{%d}',strstr,jj); tomwalters@0: newlinestr{jj}=struct2stringarray(subvari,strstrh); tomwalters@0: elseif isstr(vari{jj}) tomwalters@0: res=sprintf('%s {''%s''}',res,vari{jj}); tomwalters@0: newlinestr=sprintf('%s=[%s]',strstr,res); tomwalters@0: end tomwalters@0: end tomwalters@0: else tomwalters@0: newlinestr=sprintf('%s=''%s''',strstr,vari); tomwalters@0: end tomwalters@0: end tomwalters@0: % try tomwalters@0: if iscell(newlinestr) tomwalters@0: for oo=1:length(newlinestr) tomwalters@0: newstrcell=newlinestr{oo}; tomwalters@0: if iscell(newstrcell) tomwalters@0: for iii=1:length(newstrcell) tomwalters@0: lines{counter}=newstrcell{iii};counter=counter+1; tomwalters@0: end tomwalters@0: else tomwalters@0: lines{counter}=newstrcell;counter=counter+1; tomwalters@0: end tomwalters@0: % lines=[lines newlinestr{oo}];counter=counter+1; tomwalters@0: end tomwalters@0: else tomwalters@0: lines{counter}=newlinestr;counter=counter+1; tomwalters@0: end tomwalters@0: % catch tomwalters@0: % p=0 tomwalters@0: % end tomwalters@0: end tomwalters@0: end tomwalters@0: end tomwalters@0: else % not a struct, tomwalters@0: tomwalters@0: end