%GETDATA Retrieve data field from mapping or dataset
%
%    DATA = GETDATA(W)
%    DATA = GETDATA(W,N)
%    DATA = GETDATA(W,FIELD)
%
%    [DATA,NLAB,IDENT] = GETDATA(A,CLASSES)
%
% INPUT
%   W        Mapping
%   N        Index of cell array to be used for DATA (optional)
%   FIELD    String, name of data field structure to be retrieved
%            (optional)
%
%   A        Dataset
%   CLASSES  Indices of classes to be retrieved (optional)
%
% OUTPUT
%   DATA     Retrieved data
%   NLAB     Numeric labels of retrieved objects
%   IDENT    Object identifiers of retrieved objects 
%
% DESCRIPTION
% This routine can be used to retrieve data stored in the data fields of a
% mapping W or a dataset A.
%
% The data field of a mapping W consists of a matrix, cell array or a
% structure. If neither N nor FIELD are given, the entire data field is
% returned in DATA. If the data field is a structure, the string FIELD may
% point to the desired structure field to be returned. In case it is a cell
% array N may point to the desired element.
%
% The data field of a dataset A is an array of doubles. If the index vector 
% CLASSES is given just the data of the objects (rows of A.DATA) that belong 
% to the corresponding classes are returned. CLASSES are the class numbers
% of the classes defined in the current LABLIST. 
%
% By default all data is returned. In NLAB the class numbers of the
% selected objects are given, these are the indices to the label list that
% can be retrieved by LABLIST = GETLABLIST(A).
%
% IDENT returns the vector or cell array with the corresponding object
% identifiers stored in the IDENT field os the dataset A.
%
% SEE ALSO (<a href="http://37steps.com/prtools">PRTools Guide</a>)
% MAPPINGS, DATASETS

% $Id: getdata.m,v 1.4 2008/10/27 11:19:30 duin Exp $

function [data,nlab,ident] = getdata(a,n)
			curn = curlablist(a);
	if nargin == 2
		% extract only the requested classes
		J = [];
		for j=1:length(n)
			J = [J find(a.nlab(:,curn) == n(j))];
		end
		data = a.data(J,:);
		nlab = a.nlab(J,curn);
		ident = a.ident.ident;
		ident = ident(J,:);
		%ident = a.ident(J,:);
	else
		% extract all data
		data = a.data;
		nlab = a.nlab(:,curn);
		ident = a.ident;
	end
return

