www.gusucode.com > SVM matlab GUI可视化界面源码程序 > code/createdata/check2ddata.m

    function res=check2ddata(fname)
% 检查给定的文件是否包含二维的向量,即二维数据集
%如果文件fname中包含矩阵X [2 x num_data]和向量 y [1 x num_data],则返回1,否则返回0.

data=load( fname);

if ~isfield( data, 'X'), res=0; return; end
%tf = isfield(A, 'field')    returns logical 1 (true) if field is the name
%of a field in the structure array A, and logical 0 (false) otherwise. If A is not a structure array, isfield returns logical 0 (false).
if ~isfield( data, 'y'), res=0; return; end

if size(data.X,1) ~= 2, res=0; return; end
if size(data.X,2) ~= length(data.y), res=0; return; end

res=1;
return;