annotate aim-mat/tools/struct2stringarray.m @ 4:537f939baef0 tip

various bug fixes and changed copyright message
author Stefan Bleeck <bleeck@gmail.com>
date Tue, 16 Aug 2011 14:37:17 +0100
parents 20ada0af3d7d
children
rev   line source
tomwalters@0 1 % tool
tomwalters@0 2 %
tomwalters@0 3 % INPUT VALUES:
tomwalters@0 4 %
tomwalters@0 5 % RETURN VALUE:
tomwalters@0 6 %
bleeck@3 7 % This external file is included as part of the 'aim-mat' distribution package
bleeck@3 8 % (c) 2011, University of Southampton
bleeck@3 9 % Maintained by Stefan Bleeck (bleeck@gmail.com)
bleeck@3 10 % download of current version is on the soundsoftware site:
bleeck@3 11 % http://code.soundsoftware.ac.uk/projects/aimmat
bleeck@3 12 % documentation and everything is on http://www.acousticscale.org
bleeck@3 13
tomwalters@0 14
tomwalters@0 15 function lines=struct2stringarray(str,strname)
tomwalters@0 16 % goes recursevly through the struct and appends a line for each
tomwalters@0 17 % structthing
tomwalters@0 18
tomwalters@0 19 lines=[];
tomwalters@0 20
tomwalters@0 21 counter=1;
tomwalters@0 22 if isstruct(str)
tomwalters@0 23 names=fieldnames(str);
tomwalters@0 24 conts=struct2cell(str);
tomwalters@0 25 for i=1:length(names);
tomwalters@0 26 cstr=names{i};
tomwalters@0 27
tomwalters@0 28 nr_cont=length(str);
tomwalters@0 29 for kkk=1:nr_cont
tomwalters@0 30 if nr_cont==1
tomwalters@0 31 strstr=sprintf('%s.%s',strname,cstr);
tomwalters@0 32 else
tomwalters@0 33 strstr=sprintf('%s(%d).%s',strname,kkk,cstr);
tomwalters@0 34 end
tomwalters@0 35 % eval(sprintf('vari=str.%s;',cstr));
tomwalters@0 36 eval(sprintf('vari=str(%d).%s;',kkk,cstr));
tomwalters@0 37
tomwalters@0 38 newlinestr='';
tomwalters@0 39 if isstruct(vari)
tomwalters@0 40 newlinestr=struct2stringarray(vari,strstr);
tomwalters@0 41 nrlines=length(newlinestr);
tomwalters@0 42 for j=1:nrlines
tomwalters@0 43 lines{counter}=newlinestr{j};counter=counter+1;
tomwalters@0 44 end
tomwalters@0 45 else
tomwalters@0 46 if isnumeric(vari)
tomwalters@0 47 nrlines=size(vari,1);
tomwalters@0 48 nrcolumns=size(vari,2);
tomwalters@0 49 res='';
tomwalters@0 50 for jj=1:nrcolumns
tomwalters@0 51 for ii=1:nrlines
tomwalters@0 52 res=sprintf('%s %s',res,num2str(vari(ii,jj)));
tomwalters@0 53 end
tomwalters@0 54 if nrlines>1 && jj< nrlines
tomwalters@0 55 res=[res ';'];
tomwalters@0 56 end
tomwalters@0 57 end
tomwalters@0 58
tomwalters@0 59 if length(vari)>1
tomwalters@0 60 newlinestr=sprintf('%s=[%s]',strstr,res);
tomwalters@0 61 else
tomwalters@0 62 newlinestr=sprintf('%s=%s',strstr,num2str(vari));
tomwalters@0 63 end
tomwalters@0 64 else
tomwalters@0 65 if iscell(vari)
tomwalters@0 66 res='';
tomwalters@0 67 for jj=1:length(vari)
tomwalters@0 68 subvari=vari{jj};
tomwalters@0 69 if iscell(subvari)
tomwalters@0 70 res2='';
tomwalters@0 71 for kk=1:length(subvari)
tomwalters@0 72 res2=sprintf('%s {''%s''}',res2,subvari{kk});
tomwalters@0 73 end
tomwalters@0 74 newlinestr{jj}=sprintf('%s{%d}=[%s]',strstr,jj,res2);
tomwalters@0 75 elseif isstruct(subvari)
tomwalters@0 76 strstrh=sprintf('%s{%d}',strstr,jj);
tomwalters@0 77 newlinestr{jj}=struct2stringarray(subvari,strstrh);
tomwalters@0 78 elseif isstr(vari{jj})
tomwalters@0 79 res=sprintf('%s {''%s''}',res,vari{jj});
tomwalters@0 80 newlinestr=sprintf('%s=[%s]',strstr,res);
tomwalters@0 81 end
tomwalters@0 82 end
tomwalters@0 83 else
tomwalters@0 84 newlinestr=sprintf('%s=''%s''',strstr,vari);
tomwalters@0 85 end
tomwalters@0 86 end
tomwalters@0 87 % try
tomwalters@0 88 if iscell(newlinestr)
tomwalters@0 89 for oo=1:length(newlinestr)
tomwalters@0 90 newstrcell=newlinestr{oo};
tomwalters@0 91 if iscell(newstrcell)
tomwalters@0 92 for iii=1:length(newstrcell)
tomwalters@0 93 lines{counter}=newstrcell{iii};counter=counter+1;
tomwalters@0 94 end
tomwalters@0 95 else
tomwalters@0 96 lines{counter}=newstrcell;counter=counter+1;
tomwalters@0 97 end
tomwalters@0 98 % lines=[lines newlinestr{oo}];counter=counter+1;
tomwalters@0 99 end
tomwalters@0 100 else
tomwalters@0 101 lines{counter}=newlinestr;counter=counter+1;
tomwalters@0 102 end
tomwalters@0 103 % catch
tomwalters@0 104 % p=0
tomwalters@0 105 % end
tomwalters@0 106 end
tomwalters@0 107 end
tomwalters@0 108 end
tomwalters@0 109 else % not a struct,
tomwalters@0 110
tomwalters@0 111 end