Mercurial > hg > aimmat
annotate aim-mat/tools/units/unit classes/@unitbag/findunit.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 | 74dedb26614d |
children |
rev | line source |
---|---|
tomwalters@0 | 1 function nr=findunit(ub,unitname) |
tomwalters@0 | 2 % returns the number of the unitname in the unitbag ub |
tomwalters@0 | 3 |
tomwalters@0 | 4 units=ub.units; |
tomwalters@0 | 5 for i=1:length(units) |
tomwalters@0 | 6 unname=getname(units{i}); |
tomwalters@0 | 7 if strcmp(unname,unitname) |
tomwalters@0 | 8 nr=i; |
tomwalters@0 | 9 return |
tomwalters@0 | 10 end |
tomwalters@0 | 11 end |
tomwalters@0 | 12 % if still here then there was no exact match. Take the first oen with a |
tomwalters@0 | 13 % close match |
tomwalters@0 | 14 for i=1:length(units) |
tomwalters@0 | 15 unname=getname(units{i}); |
tomwalters@0 | 16 if ~isemtpy(strfind(unname,unitname)) |
tomwalters@0 | 17 nr=i; |
tomwalters@0 | 18 return |
tomwalters@0 | 19 end |
tomwalters@0 | 20 end |
tomwalters@0 | 21 |
tomwalters@0 | 22 % if still here then error |
tomwalters@0 | 23 error(sprintf('unit %s not found',unitname)); |
tomwalters@0 | 24 nr=-1; |
tomwalters@0 | 25 return |