www.gusucode.com > mbcguitools 工具箱 matlab 源码程序 > mbcguitools/@mbcwidgets/@VariableEditorTable/getNumericValues.m

    function vals = getNumericValues(obj, ind)
%GETNUMERICVALUES Get the numeric values for each variable
%
%  GETNUMERICVALUES(OBJ) returns a cell array where each cell contains the
%  the current vector of values for each variable.  Scalar variables are
%  guaranteed to return a single number and linked variables will return an
%  empty matrix.
%
%  GETNUMERICVALUES(OBJ, IDX) returns the values for the variables
%  specified by the vector of indices IDX.

%  Copyright 2000-2006 The MathWorks, Inc. and Ford Global Technologies, Inc.


if nargin<2
    ind = 1:length(obj.VariableNames);
end
vals = repmat({NaN}, length(ind), obj.ValueColumnCount);

Types = obj.VariableTypes;
Values = obj.VariableValues;
if obj.ValueColumnCount==1
    Types = Types(:);
    Values = Values(:);
end
szTypes = size(Types);
szValues = size(Values);

for n = 1:length(ind)
    for m = 1:min(szTypes(2), obj.ValueColumnCount)
        if ind(n)<=szTypes(1)
            if ind(n)<=szValues(1) && m<=szValues(2)
                switch Types(ind(n), m)
                    case 0
                        vals{n,m} = NaN;
                    case 1
                        if isnumeric(Values{ind(n),m})
                            vals{n,m} = Values{ind(n),m}(1);
                        else
                            vals{n,m} = NaN;
                        end
                    case 2
                        if isnumeric(Values{ind(n),m}) && length(Values{ind(n),m})==3
                            vals{n,m} = linspace(Values{ind(n),m}(1), Values{ind(n),m}(2), Values{ind(n),m}(3));
                        else
                            vals{n,m} = [];
                        end
                    case 3
                        if isnumeric(Values{ind(n),m})
                            vals{n,m} = Values{ind(n),m};
                        else
                            vals{n,m} = [];
                        end
                    case 4
                        vals{n,m} = [];
                    case 5
                        if islogical(Values{ind(n),m})
                            vals{n,m} = Values{ind(n),m}(1);
                        else
                            vals{n,m} = NaN;
                        end
                end
            else
                % Default values for each type
                switch Types(ind(n),m)
                    case {5,1,0}
                        vals{n,m} = NaN;
                    otherwise
                        vals{n,m} = [];
                end
            end
        end
    end
end