tomwalters@0: function nr=findunit(ub,unitname) tomwalters@0: % returns the number of the unitname in the unitbag ub tomwalters@0: tomwalters@0: units=ub.units; tomwalters@0: for i=1:length(units) tomwalters@0: unname=getname(units{i}); tomwalters@0: if strcmp(unname,unitname) tomwalters@0: nr=i; tomwalters@0: return tomwalters@0: end tomwalters@0: end tomwalters@0: % if still here then there was no exact match. Take the first oen with a tomwalters@0: % close match tomwalters@0: for i=1:length(units) tomwalters@0: unname=getname(units{i}); tomwalters@0: if ~isemtpy(strfind(unname,unitname)) tomwalters@0: nr=i; tomwalters@0: return tomwalters@0: end tomwalters@0: end tomwalters@0: tomwalters@0: % if still here then error tomwalters@0: error(sprintf('unit %s not found',unitname)); tomwalters@0: nr=-1; tomwalters@0: return