view toString.m @ 103:bc5db54f9efd feature/arclen-param

fzero_vec, integral_vec and spline are now local functions in Curve. Renamed arcLengthStretch to arcLengthParametrization. Removed plot_derivative. Added some comments and extra lines + removed unneccesary lines. arcLength is now a method and not static. Constructor does not accept difference operator anymore.
author Martin Almquist <martin.almquist@it.uu.se>
date Mon, 07 Dec 2015 17:24:28 +0100
parents 92247f4bad2f
children edccf4ba788b
line wrap: on
line source

% Takes a value and returns a string representation of that value.
% If syntaxFlag is true, a string with valid matlab syntax is returned.
function str = toString(value, syntaxFlag)
    default_arg('syntaxFlag',false);

    if syntaxFlag
        error('Not supported yet.')
    end

    str = value2string(value);
end

function str  = value2string(value)
    if isnumeric(value) || ischar(value) || islogical(value)
        str = mat2str(value);
    elseif isstruct(value)
        str = struct2string(value);
    elseif iscell(value)
        str = cell2string(value);
    elseif isa(value,'function_hande')
        str = func2str(value);
    else
        warning('No string representation for class ''%s''', class(value))
        str = 'NO_STR_REP';
    end
end

function str = cell2string(c)
    len = length(c);

    if len == 0
        str = '{}';
        return
    end

    str = '{';

    for i =1:len-1
        str = [str sprintf('%s, ', value2string(c{i}))];
    end
    str = [str sprintf('%s}', value2string(c{end}))];
end

function str = struct2string(s)
    fn = fieldnames(s);

    if length(fn) == 0
        str = '{}';
        return
    end

    str = '{';

    for i = 1:length(fn) - 1
        value = s.(fn{i});
        str = [str sprintf('%s: %s, ',fn{i}, value2string(value))];
    end
    value = s.(fn{end});
    str = [str sprintf('%s: %s}',fn{end}, value2string(value))];
end