% tool
% 
%   INPUT VALUES:
%  
%   RETURN VALUE:
%
% 
% (c) 2003-2008, University of Cambridge, Medical Research Council 
% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de)
% http://www.pdn.cam.ac.uk/cnbh/aim2006
% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
% $Revision: 585 $

function ret=struct2double(str,field,mmm)
% returns a field of the values in str.fild
% like: ret=str(1:12).value

nr=length(str);
if nargin < 3
    % ret=zeros(nr,1);
    for i=1:nr
        eval(sprintf('dim=length(str(1).%s);',field));
        if dim==1
            eval(sprintf('ret(%d)=str(%d).%s;',i,i,field));
        else
            eval(sprintf('ret(%d,:)=str(%d).%s;',i,i,field));
        end
    end
else
    for i=1:nr
        eval(sprintf('ret(%d,:)=str(%d).%s(%d);',i,i,field,mmm));
    end
end