text:
function [par_TIR] = read_tireparameters(filepath_tireparameters)

    %#codegen

    %% Import

    fid = fopen(filepath_tireparameters, 'r');

    % Alle relevanten Zeilen auslesen und in Cell Array "content" speichern
    content = {};

    bool_isavailable_mfsimple = false;
    bool_isavailable_mfextended = false;

    while ~feof(fid)
        line = fgetl(fid);
        if ~isempty(line)
            if strcmp(line(1), '!') == 0 && strcmp(line(1), '$') == 0 && strcmp(line(1), '[') == 0 && strcmp(line(1), '{') == 0 && strcmp(line(1), '''') == 0
                content = [content; line];
            end
        end

        % get which tire model parameters are available
        % options: five parameter MF, extended MF, both

        if contains(line, "[MFSIMPLE]")
            bool_isavailable_mfsimple = true;

        elseif contains(line, "[UNITS]")
            bool_isavailable_mfextended = true;
        end

    end

    fclose(fid);

    %% Bearbeitung: Struct erstellen und befuellen

    % Alle Leerzeichen aus den einzelnen Zellen entfernen
    for i = 1 : length(content)
        content{i} = strrep(content{i}, ' ', '');       % Leerzeichen loeschen
        content{i} = regexprep(content{i}, '\t', '');   % Tabs loeschen
    end

    if bool_isavailable_mfsimple

        % [MFSIMPLE]
        % read parameters for 5 param Pacejka tire model
        par_TIR.MFSIMPLE.PacLong_B                  = read_parameters_sub(content,'PacLong_B',filepath_tireparameters);
        par_TIR.MFSIMPLE.PacLong_C                  = read_parameters_sub(content,'PacLong_C',filepath_tireparameters);
        par_TIR.MFSIMPLE.PacLong_D                  = read_parameters_sub(content,'PacLong_D',filepath_tireparameters);
        par_TIR.MFSIMPLE.PacLong_E                  = read_parameters_sub(content,'PacLong_E',filepath_tireparameters);
        par_TIR.MFSIMPLE.PacLong_Fznom            	= read_parameters_sub(content,'PacLong_Fznom',filepath_tireparameters);
        par_TIR.MFSIMPLE.PacLong_eps_load        	= read_parameters_sub(content,'PacLong_eps_load',filepath_tireparameters);

        par_TIR.MFSIMPLE.PacLat_B                   = read_parameters_sub(content,'PacLat_B',filepath_tireparameters);
        par_TIR.MFSIMPLE.PacLat_C                   = read_parameters_sub(content,'PacLat_C',filepath_tireparameters);
        par_TIR.MFSIMPLE.PacLat_D                   = read_parameters_sub(content,'PacLat_D',filepath_tireparameters);
        par_TIR.MFSIMPLE.PacLat_E                   = read_parameters_sub(content,'PacLat_E',filepath_tireparameters);
        par_TIR.MFSIMPLE.PacLat_Fznom               = read_parameters_sub(content,'PacLat_Fznom',filepath_tireparameters);
        par_TIR.MFSIMPLE.PacLat_eps_load           	= read_parameters_sub(content,'PacLat_eps_load',filepath_tireparameters);

        par_TIR.MFSIMPLE.r_tire_m                   = read_parameters_sub(content,'r_tire_m',filepath_tireparameters);
        par_TIR.MFSIMPLE.Iyy_Wheel_kgm2             = read_parameters_sub(content,'Iyy_Wheel_kgm2',filepath_tireparameters);

    end

    if bool_isavailable_mfextended

        % [UNITS]
        ANGLE_temp                      = read_parameters_sub(content,'ANGLE',filepath_tireparameters);

        switch lower(ANGLE_temp)
            case ('degrees')
                par_TIR.ANGLE = 180 / pi;                   % unit conversion [rad] -> [degree]
            case ('radians')
                par_TIR.ANGLE = 1;
            otherwise
                error('Winkeleinheit konnte nicht bestimmt werden!');
        end

        % [MODEL]
        TYRESIDE_temp                    = read_parameters_sub(content,'TYRESIDE',filepath_tireparameters);

        switch lower(TYRESIDE_temp)
            case ('left')
                par_TIR.TYRESIDE = 1;
            case ('right')
                par_TIR.TYRESIDE = -1;
            case ('symmetric')
                par_TIR.TYRESIDE = 0;
            otherwise
                error('TYRESIDE konnte nicht bestimmt werden!');
        end

        par_TIR.USE_MODE                 = read_parameters_sub(content,'USE_MODE',filepath_tireparameters);
        par_TIR.LONGVL                              = read_parameters_sub(content,'LONGVL',filepath_tireparameters);

        % [INERTIAL]
        par_TIR.INERTIAL.m_Wheel_kg                 = read_parameters_sub(content,'m_Wheel_kg',filepath_tireparameters);
        par_TIR.INERTIAL.Iyy_Wheel_kgm2             = read_parameters_sub(content,'Iyy_Wheel_kgm2',filepath_tireparameters);

        % [WHEEL]
        par_TIR.WHEEL.br_Nmsprad                    = read_parameters_sub(content,'br_Nmsprad',filepath_tireparameters);
        par_TIR.WHEEL.FNOMIN                        = read_parameters_sub(content,'FNOMIN',filepath_tireparameters);
        par_TIR.WHEEL.NORMPRES                      = read_parameters_sub(content,'NORMPRES',filepath_tireparameters);
        par_TIR.WHEEL.TYRE_RADIUS_MOD           	= read_parameters_sub(content,'TYRE_RADIUS_MOD',filepath_tireparameters);
        par_TIR.WHEEL.T_RelaxationLong           	= read_parameters_sub(content,'T_RelaxationLong',filepath_tireparameters);
        par_TIR.WHEEL.T_RelaxationLat           	= read_parameters_sub(content,'T_RelaxationLat',filepath_tireparameters);
        par_TIR.WHEEL.T_RelaxationMy           	    = read_parameters_sub(content,'T_RelaxationMy',filepath_tireparameters);

        % [DIMENSION]
        par_TIR.DIMENSION.UNLOADED_RADIUS           = read_parameters_sub(content,'UNLOADED_RADIUS',filepath_tireparameters);
        par_TIR.DIMENSION.WIDTH                     = read_parameters_sub(content,'WIDTH',filepath_tireparameters);
        par_TIR.DIMENSION.ASPECT_RATIO              = read_parameters_sub(content,'ASPECT_RATIO',filepath_tireparameters);
        par_TIR.DIMENSION.RIM_RADIUS                = read_parameters_sub(content,'RIM_RADIUS',filepath_tireparameters);
        par_TIR.DIMENSION.RIM_WIDTH                 = read_parameters_sub(content,'RIM_WIDTH',filepath_tireparameters);

        % [VERTICAL]
        par_TIR.VERTICAL.VERTICAL_STIFFNESS         = read_parameters_sub(content,'VERTICAL_STIFFNESS',filepath_tireparameters);
        par_TIR.VERTICAL.VERTICAL_DAMPING           = read_parameters_sub(content,'VERTICAL_DAMPING',filepath_tireparameters);
        par_TIR.VERTICAL.BREFF                      = read_parameters_sub(content,'BREFF',filepath_tireparameters);
        par_TIR.VERTICAL.DREFF                      = read_parameters_sub(content,'DREFF',filepath_tireparameters);
        par_TIR.VERTICAL.FREFF                      = read_parameters_sub(content,'FREFF',filepath_tireparameters);
        % added for matlab tire model
        par_TIR.VERTICAL.Q_RE0                      = read_parameters_sub(content,'Q_RE0',filepath_tireparameters);
        par_TIR.VERTICAL.Q_V1                       = read_parameters_sub(content,'Q_V1',filepath_tireparameters);
        par_TIR.VERTICAL.Q_V2                       = read_parameters_sub(content,'Q_V2',filepath_tireparameters);
        par_TIR.VERTICAL.Q_FZ1                      = read_parameters_sub(content,'Q_FZ1',filepath_tireparameters);
        par_TIR.VERTICAL.Q_FZ2                      = read_parameters_sub(content,'Q_FZ2',filepath_tireparameters);
        par_TIR.VERTICAL.Q_FZ3                      = read_parameters_sub(content,'Q_FZ3',filepath_tireparameters);
        par_TIR.VERTICAL.Q_FCX                      = read_parameters_sub(content,'Q_FCX',filepath_tireparameters);
        par_TIR.VERTICAL.Q_FCY                      = read_parameters_sub(content,'Q_FCY',filepath_tireparameters);
        par_TIR.VERTICAL.Q_FCY2                     = read_parameters_sub(content,'Q_FCY2',filepath_tireparameters);
        par_TIR.VERTICAL.PFZ1                       = read_parameters_sub(content,'PFZ1',filepath_tireparameters);

        % [SIMULATION]
        par_TIR.SIMULATION.KPUMIN                   = read_parameters_sub(content,'KPUMIN',filepath_tireparameters);
        par_TIR.SIMULATION.KPUMAX                   = read_parameters_sub(content,'KPUMAX',filepath_tireparameters);
        par_TIR.SIMULATION.ALPMIN                   = read_parameters_sub(content,'ALPMIN',filepath_tireparameters);
        par_TIR.SIMULATION.ALPMAX                   = read_parameters_sub(content,'ALPMAX',filepath_tireparameters);
        par_TIR.SIMULATION.CAMMIN                   = read_parameters_sub(content,'CAMMIN',filepath_tireparameters);
        par_TIR.SIMULATION.CAMMAX                   = read_parameters_sub(content,'CAMMAX',filepath_tireparameters);
        par_TIR.SIMULATION.FZMIN                    = read_parameters_sub(content,'FZMIN',filepath_tireparameters);
        par_TIR.SIMULATION.FZMAX                    = read_parameters_sub(content,'FZMAX',filepath_tireparameters);
        par_TIR.SIMULATION.LONGVL                   = read_parameters_sub(content,'LONGVL',filepath_tireparameters);
        % added for matlab tire model
        par_TIR.SIMULATION.VXLOW                    = read_parameters_sub(content,'VXLOW',filepath_tireparameters);
        par_TIR.SIMULATION.PRESMIN               	= read_parameters_sub(content,'PRESMIN',filepath_tireparameters);
        par_TIR.SIMULATION.PRESMAX               	= read_parameters_sub(content,'PRESMAX',filepath_tireparameters);

        % [SCALING_COEFFICIENTS]
        par_TIR.SCALING.LFZO                     = read_parameters_sub(content,'LFZO',filepath_tireparameters);
        par_TIR.SCALING.LCX                      = read_parameters_sub(content,'LCX',filepath_tireparameters);
        par_TIR.SCALING.LMUX                     = read_parameters_sub(content,'LMUX',filepath_tireparameters);
        par_TIR.SCALING.LEX                      = read_parameters_sub(content,'LEX',filepath_tireparameters);
        par_TIR.SCALING.LKX                      = read_parameters_sub(content,'LKX',filepath_tireparameters);
        par_TIR.SCALING.LHX                      = read_parameters_sub(content,'LHX',filepath_tireparameters);
        par_TIR.SCALING.LVX                      = read_parameters_sub(content,'LVX',filepath_tireparameters);
        par_TIR.SCALING.LGAX                     = read_parameters_sub(content,'LGAX',filepath_tireparameters);
        par_TIR.SCALING.LCY                      = read_parameters_sub(content,'LCY',filepath_tireparameters);
        par_TIR.SCALING.LMUY                     = read_parameters_sub(content,'LMUY',filepath_tireparameters);
        par_TIR.SCALING.LEY                      = read_parameters_sub(content,'LEY',filepath_tireparameters);
        par_TIR.SCALING.LKY                      = read_parameters_sub(content,'LKY',filepath_tireparameters);
        par_TIR.SCALING.LHY                      = read_parameters_sub(content,'LHY',filepath_tireparameters);
        par_TIR.SCALING.LVY                      = read_parameters_sub(content,'LVY',filepath_tireparameters);
        par_TIR.SCALING.LGAY                     = read_parameters_sub(content,'LGAY',filepath_tireparameters);
        par_TIR.SCALING.LTR                      = read_parameters_sub(content,'LTR',filepath_tireparameters);
        par_TIR.SCALING.LRES                     = read_parameters_sub(content,'LRES',filepath_tireparameters);
        par_TIR.SCALING.LGAZ                     = read_parameters_sub(content,'LGAZ',filepath_tireparameters);
        par_TIR.SCALING.LXAL                     = read_parameters_sub(content,'LXAL',filepath_tireparameters);
        par_TIR.SCALING.LYKA                     = read_parameters_sub(content,'LYKA',filepath_tireparameters);
        par_TIR.SCALING.LVYKA                    = read_parameters_sub(content,'LVYKA',filepath_tireparameters);
        par_TIR.SCALING.LS                       = read_parameters_sub(content,'LS',filepath_tireparameters);
        par_TIR.SCALING.LSGKP                    = read_parameters_sub(content,'LSGKP',filepath_tireparameters);
        par_TIR.SCALING.LSGAL                    = read_parameters_sub(content,'LSGAL',filepath_tireparameters);
        par_TIR.SCALING.LGYR                     = read_parameters_sub(content,'LGYR',filepath_tireparameters);
        par_TIR.SCALING.LMX                      = read_parameters_sub(content,'LMX',filepath_tireparameters);
        par_TIR.SCALING.LVMX                     = read_parameters_sub(content,'LVMX',filepath_tireparameters);
        par_TIR.SCALING.LMY                      = read_parameters_sub(content,'LMY',filepath_tireparameters);
        % added for matlab tire model
        par_TIR.SCALING.LMUV                     = read_parameters_sub(content,'LMUV',filepath_tireparameters);
        par_TIR.SCALING.LCZ                      = read_parameters_sub(content,'LCZ',filepath_tireparameters);
        par_TIR.SCALING.LMPHI                    = read_parameters_sub(content,'LMPHI',filepath_tireparameters);

        % [LONGITUDINAL_COEFFICIENTS]
        par_TIR.LONGITUDINAL.PCX1                     = read_parameters_sub(content,'PCX1',filepath_tireparameters);
        par_TIR.LONGITUDINAL.PDX1                     = read_parameters_sub(content,'PDX1',filepath_tireparameters);
        par_TIR.LONGITUDINAL.PDX2                     = read_parameters_sub(content,'PDX2',filepath_tireparameters);
        par_TIR.LONGITUDINAL.PDX3                     = read_parameters_sub(content,'PDX3',filepath_tireparameters);
        par_TIR.LONGITUDINAL.PEX1                     = read_parameters_sub(content,'PEX1',filepath_tireparameters);
        par_TIR.LONGITUDINAL.PEX2                     = read_parameters_sub(content,'PEX2',filepath_tireparameters);
        par_TIR.LONGITUDINAL.PEX3                     = read_parameters_sub(content,'PEX3',filepath_tireparameters);
        par_TIR.LONGITUDINAL.PEX4                     = read_parameters_sub(content,'PEX4',filepath_tireparameters);
        par_TIR.LONGITUDINAL.PKX1                     = read_parameters_sub(content,'PKX1',filepath_tireparameters);
        par_TIR.LONGITUDINAL.PKX2                     = read_parameters_sub(content,'PKX2',filepath_tireparameters);
        par_TIR.LONGITUDINAL.PKX3                     = read_parameters_sub(content,'PKX3',filepath_tireparameters);
        par_TIR.LONGITUDINAL.PHX1                     = read_parameters_sub(content,'PHX1',filepath_tireparameters);
        par_TIR.LONGITUDINAL.PHX2                     = read_parameters_sub(content,'PHX2',filepath_tireparameters);
        par_TIR.LONGITUDINAL.PVX1                     = read_parameters_sub(content,'PVX1',filepath_tireparameters);
        par_TIR.LONGITUDINAL.PVX2                     = read_parameters_sub(content,'PVX2',filepath_tireparameters);
        par_TIR.LONGITUDINAL.RBX1                     = read_parameters_sub(content,'RBX1',filepath_tireparameters);
        par_TIR.LONGITUDINAL.RBX2                     = read_parameters_sub(content,'RBX2',filepath_tireparameters);
        par_TIR.LONGITUDINAL.RCX1                     = read_parameters_sub(content,'RCX1',filepath_tireparameters);
        par_TIR.LONGITUDINAL.REX1                     = read_parameters_sub(content,'REX1',filepath_tireparameters);
        par_TIR.LONGITUDINAL.REX2                     = read_parameters_sub(content,'REX2',filepath_tireparameters);
        par_TIR.LONGITUDINAL.RHX1                     = read_parameters_sub(content,'RHX1',filepath_tireparameters);
        par_TIR.LONGITUDINAL.PTX1                     = read_parameters_sub(content,'PTX1',filepath_tireparameters);
        par_TIR.LONGITUDINAL.PTX2                     = read_parameters_sub(content,'PTX2',filepath_tireparameters);
        par_TIR.LONGITUDINAL.PTX3                     = read_parameters_sub(content,'PTX3',filepath_tireparameters);
        % added for matlab tire model
        par_TIR.LONGITUDINAL.PPX1                     = read_parameters_sub(content,'PPX1',filepath_tireparameters);
        par_TIR.LONGITUDINAL.PPX2                     = read_parameters_sub(content,'PPX2',filepath_tireparameters);
        par_TIR.LONGITUDINAL.PPX3                     = read_parameters_sub(content,'PPX3',filepath_tireparameters);
        par_TIR.LONGITUDINAL.PPX4                     = read_parameters_sub(content,'PPX4',filepath_tireparameters);
        par_TIR.LONGITUDINAL.RBX3                     = read_parameters_sub(content,'RBX3',filepath_tireparameters);

        % [OVERTURNING_COEFFICIENTS]
        par_TIR.OVERTURNING.QSX1                     = read_parameters_sub(content,'QSX1',filepath_tireparameters);
        par_TIR.OVERTURNING.QSX2                     = read_parameters_sub(content,'QSX2',filepath_tireparameters);
        par_TIR.OVERTURNING.QSX3                     = read_parameters_sub(content,'QSX3',filepath_tireparameters);
        % added for matlab tire model
        par_TIR.OVERTURNING.QSX4                     = read_parameters_sub(content,'QSX4',filepath_tireparameters);
        par_TIR.OVERTURNING.QSX5                     = read_parameters_sub(content,'QSX5',filepath_tireparameters);
        par_TIR.OVERTURNING.QSX6                     = read_parameters_sub(content,'QSX6',filepath_tireparameters);
        par_TIR.OVERTURNING.QSX7                     = read_parameters_sub(content,'QSX7',filepath_tireparameters);
        par_TIR.OVERTURNING.QSX8                     = read_parameters_sub(content,'QSX8',filepath_tireparameters);
        par_TIR.OVERTURNING.QSX9                     = read_parameters_sub(content,'QSX9',filepath_tireparameters);
        par_TIR.OVERTURNING.QSX10                    = read_parameters_sub(content,'QSX10',filepath_tireparameters);
        par_TIR.OVERTURNING.QSX11                    = read_parameters_sub(content,'QSX11',filepath_tireparameters);
        par_TIR.OVERTURNING.QSX12                    = read_parameters_sub(content,'QSX12',filepath_tireparameters);
        par_TIR.OVERTURNING.QSX13                    = read_parameters_sub(content,'QSX13',filepath_tireparameters);
        par_TIR.OVERTURNING.QSX14                    = read_parameters_sub(content,'QSX14',filepath_tireparameters);
        par_TIR.OVERTURNING.PPMX1                    = read_parameters_sub(content,'PPMX1',filepath_tireparameters);

        % [LATERAL_COEFFICIENTS]
        par_TIR.LATERAL.PCY1                     = read_parameters_sub(content,'PCY1',filepath_tireparameters);
        par_TIR.LATERAL.PDY1                     = read_parameters_sub(content,'PDY1',filepath_tireparameters);
        par_TIR.LATERAL.PDY2                     = read_parameters_sub(content,'PDY2',filepath_tireparameters);
        par_TIR.LATERAL.PDY3                     = read_parameters_sub(content,'PDY3',filepath_tireparameters);
        par_TIR.LATERAL.PEY1                     = read_parameters_sub(content,'PEY1',filepath_tireparameters);
        par_TIR.LATERAL.PEY2                     = read_parameters_sub(content,'PEY2',filepath_tireparameters);
        par_TIR.LATERAL.PEY3                     = read_parameters_sub(content,'PEY3',filepath_tireparameters);
        par_TIR.LATERAL.PEY4                     = read_parameters_sub(content,'PEY4',filepath_tireparameters);
        par_TIR.LATERAL.PKY1                     = read_parameters_sub(content,'PKY1',filepath_tireparameters);
        par_TIR.LATERAL.PKY2                     = read_parameters_sub(content,'PKY2',filepath_tireparameters);
        par_TIR.LATERAL.PKY3                     = read_parameters_sub(content,'PKY3',filepath_tireparameters);
        par_TIR.LATERAL.PHY1                     = read_parameters_sub(content,'PHY1',filepath_tireparameters);
        par_TIR.LATERAL.PHY2                     = read_parameters_sub(content,'PHY2',filepath_tireparameters);
        par_TIR.LATERAL.PHY3                     = read_parameters_sub(content,'PHY3',filepath_tireparameters);
        par_TIR.LATERAL.PVY1                     = read_parameters_sub(content,'PVY1',filepath_tireparameters);
        par_TIR.LATERAL.PVY2                     = read_parameters_sub(content,'PVY2',filepath_tireparameters);
        par_TIR.LATERAL.PVY3                     = read_parameters_sub(content,'PVY3',filepath_tireparameters);
        par_TIR.LATERAL.PVY4                     = read_parameters_sub(content,'PVY4',filepath_tireparameters);
        par_TIR.LATERAL.RBY1                     = read_parameters_sub(content,'RBY1',filepath_tireparameters);
        par_TIR.LATERAL.RBY2                     = read_parameters_sub(content,'RBY2',filepath_tireparameters);
        par_TIR.LATERAL.RBY3                     = read_parameters_sub(content,'RBY3',filepath_tireparameters);
        par_TIR.LATERAL.RCY1                     = read_parameters_sub(content,'RCY1',filepath_tireparameters);
        par_TIR.LATERAL.REY1                     = read_parameters_sub(content,'REY1',filepath_tireparameters);
        par_TIR.LATERAL.REY2                     = read_parameters_sub(content,'REY2',filepath_tireparameters);
        par_TIR.LATERAL.RHY1                     = read_parameters_sub(content,'RHY1',filepath_tireparameters);
        par_TIR.LATERAL.RHY2                     = read_parameters_sub(content,'RHY2',filepath_tireparameters);
        par_TIR.LATERAL.RVY1                     = read_parameters_sub(content,'RVY1',filepath_tireparameters);
        par_TIR.LATERAL.RVY2                     = read_parameters_sub(content,'RVY2',filepath_tireparameters);
        par_TIR.LATERAL.RVY3                     = read_parameters_sub(content,'RVY3',filepath_tireparameters);
        par_TIR.LATERAL.RVY4                     = read_parameters_sub(content,'RVY4',filepath_tireparameters);
        par_TIR.LATERAL.RVY5                     = read_parameters_sub(content,'RVY5',filepath_tireparameters);
        par_TIR.LATERAL.RVY6                     = read_parameters_sub(content,'RVY6',filepath_tireparameters);
        par_TIR.LATERAL.PTY1                     = read_parameters_sub(content,'PTY1',filepath_tireparameters);
        par_TIR.LATERAL.PTY2                     = read_parameters_sub(content,'PTY2',filepath_tireparameters);
        % added for matlab tire model
        par_TIR.LATERAL.PEY5                     = read_parameters_sub(content,'PEY5',filepath_tireparameters);
        par_TIR.LATERAL.PKY4                     = read_parameters_sub(content,'PKY4',filepath_tireparameters);
        par_TIR.LATERAL.PKY5                     = read_parameters_sub(content,'PKY5',filepath_tireparameters);
        par_TIR.LATERAL.PKY6                     = read_parameters_sub(content,'PKY6',filepath_tireparameters);
        par_TIR.LATERAL.PKY7                     = read_parameters_sub(content,'PKY7',filepath_tireparameters);
        par_TIR.LATERAL.PPY1                     = read_parameters_sub(content,'PPY1',filepath_tireparameters);
        par_TIR.LATERAL.PPY2                     = read_parameters_sub(content,'PPY2',filepath_tireparameters);
        par_TIR.LATERAL.PPY3                     = read_parameters_sub(content,'PPY3',filepath_tireparameters);
        par_TIR.LATERAL.PPY4                     = read_parameters_sub(content,'PPY4',filepath_tireparameters);
        par_TIR.LATERAL.PPY5                     = read_parameters_sub(content,'PPY5',filepath_tireparameters);
        par_TIR.LATERAL.RBY4                     = read_parameters_sub(content,'RBY4',filepath_tireparameters);

        % [ROLLING_COEFFICIENTS]
        par_TIR.ROLLING.QSY1                     = read_parameters_sub(content,'QSY1',filepath_tireparameters);
        par_TIR.ROLLING.QSY2                     = read_parameters_sub(content,'QSY2',filepath_tireparameters);
        par_TIR.ROLLING.QSY3                     = read_parameters_sub(content,'QSY3',filepath_tireparameters);
        par_TIR.ROLLING.QSY4                     = read_parameters_sub(content,'QSY4',filepath_tireparameters);
        % added for matlab tire model
        par_TIR.ROLLING.QSY5                     = read_parameters_sub(content,'QSY5',filepath_tireparameters);
        par_TIR.ROLLING.QSY6                     = read_parameters_sub(content,'QSY6',filepath_tireparameters);
        par_TIR.ROLLING.QSY7                     = read_parameters_sub(content,'QSY7',filepath_tireparameters);
        par_TIR.ROLLING.QSY8                     = read_parameters_sub(content,'QSY8',filepath_tireparameters);

        % [ALIGNING_COEFFICIENTS]
        par_TIR.ALIGNING.QBZ1                     = read_parameters_sub(content,'QBZ1',filepath_tireparameters);
        par_TIR.ALIGNING.QBZ2                     = read_parameters_sub(content,'QBZ2',filepath_tireparameters);
        par_TIR.ALIGNING.QBZ3                     = read_parameters_sub(content,'QBZ3',filepath_tireparameters);
        par_TIR.ALIGNING.QBZ4                     = read_parameters_sub(content,'QBZ4',filepath_tireparameters);
        par_TIR.ALIGNING.QBZ5                     = read_parameters_sub(content,'QBZ5',filepath_tireparameters);
        par_TIR.ALIGNING.QBZ9                     = read_parameters_sub(content,'QBZ9',filepath_tireparameters);
        par_TIR.ALIGNING.QBZ10                    = read_parameters_sub(content,'QBZ10',filepath_tireparameters);
        par_TIR.ALIGNING.QCZ1                     = read_parameters_sub(content,'QCZ1',filepath_tireparameters);
        par_TIR.ALIGNING.QDZ1                     = read_parameters_sub(content,'QDZ1',filepath_tireparameters);
        par_TIR.ALIGNING.QDZ2                     = read_parameters_sub(content,'QDZ2',filepath_tireparameters);
        par_TIR.ALIGNING.QDZ3                     = read_parameters_sub(content,'QDZ3',filepath_tireparameters);
        par_TIR.ALIGNING.QDZ4                     = read_parameters_sub(content,'QDZ4',filepath_tireparameters);
        par_TIR.ALIGNING.QDZ6                     = read_parameters_sub(content,'QDZ6',filepath_tireparameters);
        par_TIR.ALIGNING.QDZ7                     = read_parameters_sub(content,'QDZ7',filepath_tireparameters);
        par_TIR.ALIGNING.QDZ8                     = read_parameters_sub(content,'QDZ8',filepath_tireparameters);
        par_TIR.ALIGNING.QDZ9                     = read_parameters_sub(content,'QDZ9',filepath_tireparameters);
        par_TIR.ALIGNING.QEZ1                     = read_parameters_sub(content,'QEZ1',filepath_tireparameters);
        par_TIR.ALIGNING.QEZ2                     = read_parameters_sub(content,'QEZ2',filepath_tireparameters);
        par_TIR.ALIGNING.QEZ3                     = read_parameters_sub(content,'QEZ3',filepath_tireparameters);
        par_TIR.ALIGNING.QEZ4                     = read_parameters_sub(content,'QEZ4',filepath_tireparameters);
        par_TIR.ALIGNING.QEZ5                     = read_parameters_sub(content,'QEZ5',filepath_tireparameters);
        par_TIR.ALIGNING.QHZ1                     = read_parameters_sub(content,'QHZ1',filepath_tireparameters);
        par_TIR.ALIGNING.QHZ2                     = read_parameters_sub(content,'QHZ2',filepath_tireparameters);
        par_TIR.ALIGNING.QHZ3                     = read_parameters_sub(content,'QHZ3',filepath_tireparameters);
        par_TIR.ALIGNING.QHZ4                     = read_parameters_sub(content,'QHZ4',filepath_tireparameters);
        par_TIR.ALIGNING.SSZ1                     = read_parameters_sub(content,'SSZ1',filepath_tireparameters);
        par_TIR.ALIGNING.SSZ2                     = read_parameters_sub(content,'SSZ2',filepath_tireparameters);
        par_TIR.ALIGNING.SSZ3                     = read_parameters_sub(content,'SSZ3',filepath_tireparameters);
        par_TIR.ALIGNING.SSZ4                     = read_parameters_sub(content,'SSZ4',filepath_tireparameters);
        par_TIR.ALIGNING.QTZ1                     = read_parameters_sub(content,'QTZ1',filepath_tireparameters);
        par_TIR.ALIGNING.MBELT                    = read_parameters_sub(content,'MBELT',filepath_tireparameters);
        % added for matlab tire model
        par_TIR.ALIGNING.QBZ6                     = read_parameters_sub(content,'QBZ6',filepath_tireparameters);
        par_TIR.ALIGNING.QDZ10                    = read_parameters_sub(content,'QDZ10',filepath_tireparameters);
        par_TIR.ALIGNING.QDZ11                    = read_parameters_sub(content,'QDZ11',filepath_tireparameters);
        par_TIR.ALIGNING.PPZ1                    = read_parameters_sub(content,'PPZ1',filepath_tireparameters);
        par_TIR.ALIGNING.PPZ2                    = read_parameters_sub(content,'PPZ2',filepath_tireparameters);

        % TURNSLIP completely added for Matlab tire MODEL
        % [TURNSLIP]
        par_TIR.TURNSLIP.PDXP1                     = read_parameters_sub(content,'PDXP1',filepath_tireparameters);
        par_TIR.TURNSLIP.PDXP2                     = read_parameters_sub(content,'PDXP2',filepath_tireparameters);
        par_TIR.TURNSLIP.PDXP3                     = read_parameters_sub(content,'PDXP3',filepath_tireparameters);
        par_TIR.TURNSLIP.PKYP1                     = read_parameters_sub(content,'PKYP1',filepath_tireparameters);
        par_TIR.TURNSLIP.PDYP1                     = read_parameters_sub(content,'PDYP1',filepath_tireparameters);
        par_TIR.TURNSLIP.PDYP2                     = read_parameters_sub(content,'PDYP2',filepath_tireparameters);
        par_TIR.TURNSLIP.PDYP3                     = read_parameters_sub(content,'PDYP3',filepath_tireparameters);
        par_TIR.TURNSLIP.PDYP4                     = read_parameters_sub(content,'PDYP4',filepath_tireparameters);
        par_TIR.TURNSLIP.PHYP1                     = read_parameters_sub(content,'PHYP1',filepath_tireparameters);
        par_TIR.TURNSLIP.PHYP2                     = read_parameters_sub(content,'PHYP2',filepath_tireparameters);
        par_TIR.TURNSLIP.PHYP3                     = read_parameters_sub(content,'PHYP3',filepath_tireparameters);
        par_TIR.TURNSLIP.PHYP4                     = read_parameters_sub(content,'PHYP4',filepath_tireparameters);
        par_TIR.TURNSLIP.PECP1                     = read_parameters_sub(content,'PECP1',filepath_tireparameters);
        par_TIR.TURNSLIP.PECP2                     = read_parameters_sub(content,'PECP2',filepath_tireparameters);
        par_TIR.TURNSLIP.QDTP1                     = read_parameters_sub(content,'QDTP1',filepath_tireparameters);
        par_TIR.TURNSLIP.QCRP1                     = read_parameters_sub(content,'QCRP1',filepath_tireparameters);
        par_TIR.TURNSLIP.QCRP2                     = read_parameters_sub(content,'QCRP2',filepath_tireparameters);
        par_TIR.TURNSLIP.QBRP1                     = read_parameters_sub(content,'QBRP1',filepath_tireparameters);
        par_TIR.TURNSLIP.QDRP1                     = read_parameters_sub(content,'QDRP1',filepath_tireparameters);
        par_TIR.TURNSLIP.QDRP2                     = read_parameters_sub(content,'QDRP2',filepath_tireparameters);

        % CONTACTPATCH completely added for Matlab tire MODEL
        % [CONTACTPATCH]
        par_TIR.CONTACTPATCH.Q_RA1                   = read_parameters_sub(content,'Q_RA1',filepath_tireparameters);
        par_TIR.CONTACTPATCH.Q_RA2                   = read_parameters_sub(content,'Q_RA2',filepath_tireparameters);
        par_TIR.CONTACTPATCH.Q_RB1                   = read_parameters_sub(content,'Q_RB1',filepath_tireparameters);
        par_TIR.CONTACTPATCH.Q_RB2                   = read_parameters_sub(content,'Q_RB2',filepath_tireparameters);

        % STRUCTURAL completely added for Matlab tire MODEL
        % [STRUCTURAL]
        par_TIR.STRUCTURAL.LONGITUDINAL_STIFFNESS     = read_parameters_sub(content,'LONGITUDINAL_STIFFNESS',filepath_tireparameters);
        par_TIR.STRUCTURAL.LATERAL_STIFFNESS          = read_parameters_sub(content,'LATERAL_STIFFNESS',filepath_tireparameters);
        par_TIR.STRUCTURAL.PCFX1                      = read_parameters_sub(content,'PCFX1',filepath_tireparameters);
        par_TIR.STRUCTURAL.PCFX2                      = read_parameters_sub(content,'PCFX2',filepath_tireparameters);
        par_TIR.STRUCTURAL.PCFX3                      = read_parameters_sub(content,'PCFX3',filepath_tireparameters);
        par_TIR.STRUCTURAL.PCFY1                      = read_parameters_sub(content,'PCFY1',filepath_tireparameters);
        par_TIR.STRUCTURAL.PCFY2                      = read_parameters_sub(content,'PCFY2',filepath_tireparameters);
        par_TIR.STRUCTURAL.PCFY3                      = read_parameters_sub(content,'PCFY3',filepath_tireparameters);

        % GENERAL completely added for Matlab tire MODEL
        % [GENERAL]
        par_TIR.CONTACTPATCH.k1_TireFB_PT1              = read_parameters_sub(content,'k1_TireFB_PT1',filepath_tireparameters);
        par_TIR.CONTACTPATCH.k1_WheelsFB_PT1            = read_parameters_sub(content,'k1_WheelsFB_PT1',filepath_tireparameters);
        par_TIR.CONTACTPATCH.k2_TireFB_PT1              = read_parameters_sub(content,'k2_TireFB_PT1',filepath_tireparameters);
        par_TIR.CONTACTPATCH.p_Tires_Pa                 = read_parameters_sub(content,'p_Tires_Pa',filepath_tireparameters);

    end

end

author: TUMFTM


text:
% This script defines a project shortcut.
%
% To get a handle to the current project use the following function:
%
% project = simulinkproject();
%
% You can use the fields of project to get information about the currently
% loaded project.
%
% See: help simulinkproject

project = simulinkproject;
projectRoot = project.RootFolder;

try
  % check if build folder exists and clean it up
  if(exist([projectRoot '/build'], 'dir'))
    rmdir([projectRoot '/build'], 's');
  end
  % create an empty build directory
  mkdir([projectRoot '/build']);
  disp('Build folder setup done.');
catch e
    disp('Exception: ');
    disp(getReport(e))
    error('Setup of build folder failed.');
end

myCacheFolder = fullfile(projectRoot, 'build');
myCodeFolder = fullfile(projectRoot, 'build');

Simulink.fileGenControl('set',...
    'CacheFolder', myCacheFolder,...
    'CodeGenFolder', myCodeFolder,...
    'createDir', true)


text:
function minDosage(tFit, pFit)
% This function accepts response surface models, and determines the minimal
% drug concentrations that results in pressure and tetany responses > 0.98.
%
% Copyright 2011 The MathWorks, Inc.

% Create a Grid to Evaluate Surface Fits
[op, sed] = meshgrid(linspace(0,50,50), linspace(0,10,50));
op = op(:);
sed = sed(:);

% Evaluate Surface Fit on Grid
sfT = tFit(op,sed);
sfP = pFit(op,sed);

% Find Cutoff For a Particular Pressure and Tetany Condition
cutoffT = sfT > 0.98;
cutoffP = sfP > 0.98;
idx = cutoffT & cutoffP;
opN = op(idx); sedN = sed(idx);

% Find and Display Minimal Drug Concentrations
drugDist = hypot(opN/50,sedN/10);
[cMin,id] = min(drugDist);
opMin = opN(id);
sedMin = sedN(id);

disp('Minimal Drug Concentrations -')
disp(['Opioid: ', num2str(opMin), ', Sedative: ', num2str(sedMin)])

% Plot minimal drug concentrations on tetany contour plot
figure;
plot(tFit, 'Style', 'contour');
colorbar;
xlabel('opiod', 'FontSize', 12);
ylabel('sedative', 'FontSize', 12);
title('Minimal Doses (Tetany)', 'FontSize', 14);
hold on
plot3(op,sed,tFit(op,sed),'k.')
plot3(opMin,sedMin,tFit(opMin,sedMin),'py','MarkerFaceColor',...
      'y','MarkerSize', 10)

% Plot minimal drug concentrations on pressure contour plot
figure;
plot(pFit, 'Style', 'contour');
colorbar;
xlabel('opiod', 'FontSize', 12);
ylabel('sedative', 'FontSize', 12);
title('Minimal Doses (Pressure)', 'FontSize', 14);
hold on
plot3(op,sed,pFit(op,sed),'k.')
plot3(opMin,sedMin,pFit(opMin,sedMin),'py','MarkerFaceColor',...
      'y','MarkerSize', 10)

author: Sable

repo: mcbench-benchmarks


text:
function determ = herndon_determinant ( n )

%*****************************************************************************80
%
%% HERNDON_DETERMINANT returns the determinant of the Herndon matrix.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    11 October 2007
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, integer N, the order of A.
%
%    Output, real DETERM, the determinant.
%
  determ = 6.0 / ( ( n + 1 ) * n * ( 5 - 2 * n ) );

  return
end

author: johannesgerer

repo: jburkardt-m


text:
function varargout = compressione_help(varargin)
% COMPRESSIONE_HELP M-file for compressione_help.fig
%      COMPRESSIONE_HELP, by itself, creates a new COMPRESSIONE_HELP or raises the existing
%      singleton*.
%
%      H = COMPRESSIONE_HELP returns the handle to a new COMPRESSIONE_HELP or the handle to
%      the existing singleton*.
%
%      COMPRESSIONE_HELP('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in COMPRESSIONE_HELP.M with the given input arguments.
%
%      COMPRESSIONE_HELP('Property','Value',...) creates a new COMPRESSIONE_HELP or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before compressione_help_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to compressione_help_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help compressione_help

% Last Modified by GUIDE v2.5 16-Jun-2010 18:52:11

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @compressione_help_OpeningFcn, ...
                   'gui_OutputFcn',  @compressione_help_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT

% --- Executes just before compressione_help is made visible.
function compressione_help_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to compressione_help (see VARARGIN)

% Choose default command line output for compressione_help
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes compressione_help wait for user response (see UIRESUME)
% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = compressione_help_OutputFcn(hObject, eventdata, handles)
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


text:
function [L,D] = ldldecom(Q)
%LDLDECOM: Find LtDL-decompostion of Q-matrix
%
% This routine finds the LtDL decomposition of a given variance/
% covariance matrix.
%
% Input arguments:
%    Q: Symmetric n by n matrix to be factored
%
% Output arguments:
%    L: Out - n by n factor matrix (strict lower triangular)
%    D: Out - Diagonal n-vector

% ----------------------------------------------------------------------
% File.....: ldldecom
% Date.....: 19-MAY-1999
% Author...: Peter Joosten
%            Mathematical Geodesy and Positioning
%            Delft University of Technology
% ----------------------------------------------------------------------

n = size (Q,1);

for i = n:-1:1;

   D(i) = Q(i,i);
   L(i,1:i) = Q(i,1:i)/sqrt(Q(i,i));

   for j = 1:i-1
      Q(j,1:j) = Q(j,1:j)-L(i,1:j)*L(i,j);
   end

   L(i,1:i) = L(i,1:i)/L(i,i);

end;

if (sum(D < 1E-10));

  error ('Matrix on input is not positive definite!');

end;

% ----------------------------------------------------------------------
% End of routine: ldldecom
% ----------------------------------------------------------------------

author: goGPS-Project


text:
function err = test_performance
%TEST_PERFORMANCE compare performance of factorization/solve methods.
% Returns the largest relative residual seen.
%
% Example
%   err = test_performance
%
% See also test_all, test_factorize, factorize, inverse, mldivide

% Copyright 2009, Timothy A. Davis, University of Florida

fprintf ('\nPerformance comparisons of 5 methods:\n') ;
fprintf ('    backslash: A\\b, or L\\b (and related) for solve times.\n') ;
fprintf ('    linsolve:  a built-in MATLAB function\n') ;
fprintf ('    factorize1:  the simple factorization object (uses LU)\n') ;
fprintf ('    factorize:  the full-featured factorization object\n') ;
fprintf ('    inv: x=inv(A)*b, the explicit inverse (ack!)\n') ;
fprintf ('Run times are in seconds.\n') ;
fprintf ('Times relative to best times are in parentheses.\n') ;

% linsolve options:
A_is_posdef.POSDEF = true ;     % for x = A\b where A is sym. pos. definite
A_is_posdef.SYM = true ;
lsolve.LT = true ;              % for x = L\b where L is lower triangular
usolve.UT = true ;              % for x = U\b where U is upper triangular
ltsolve.LT = true ;             % for x = L'b where L is lower triangular
ltsolve.TRANSA = true ;

nn = [50 100 500 1000] ;        % matrix sizes to test
ns = length (nn) ;
tmax = 1 ;                      % minimum testing time
err = 0 ;                       % largest relative residual seen

for posdef = 0:1

    if (posdef)
        fprintf ('\n------------------ For positive definite matrices:\n') ;
    else
        fprintf ('\n------------------ For unsymmetric matrices:\n') ;
    end

    Tfactor = zeros (ns,5) ;
    Tsolve  = zeros (ns,5) ;

    %-----------------------------------------------------------------------
    % compare factorizations times (plus a single solve)
    %-----------------------------------------------------------------------

    fprintf ('\nCompare factorization times:\n') ;
    for i = 1:ns
        n = nn (i) ;

        fprintf ('n %4d ', n) ;

        A = rand (n) ;
        if (posdef)
            A = A'*A + eye (n) ;
        end
        anorm = norm (A,1) ;
        b = rand (n,1) ;

        % method 1: backslash
        t = 0 ;
        k = 0 ;
        tic
        while (t < tmax)
            x = A\b ;
            k = k + 1 ;
            t = toc ;
        end
        Tfactor (i,1) = t / k ;
        err = max (err, norm (A*x-b,1) / (anorm + norm (x,1))) ;
        clear x

        if (posdef)

            % method 2: linsolve (pos. definite case)
            t = 0 ;
            k = 0 ;
            tic
            while (t < tmax)
                x = linsolve (A,b, A_is_posdef) ;
                k = k + 1 ;
                t = toc ;
            end
            Tfactor (i,2) = t / k ;
            err = max (err, norm (A*x-b,1) / (anorm + norm (x,1))) ;
            clear x

        else

            % method 2: linsolve (unsymmetric case)
            t = 0 ;
            k = 0 ;
            tic
            while (t < tmax)
                x = linsolve (A,b) ;
                k = k + 1 ;
                t = toc ;
            end
            Tfactor (i,2) = t / k ;
            err = max (err, norm (A*x-b,1) / (anorm + norm (x,1))) ;
            clear x

        end

        % method 3: factorize1 method
        t = 0 ;
        k = 0 ;
        tic
        while (t < tmax)
            F = factorize1 (A) ;
            x = F\b ;
            k = k + 1 ;
            t = toc ;
        end
        Tfactor (i,3) = t / k ;
        err = max (err, norm (A*x-b,1) / (anorm + norm (x,1))) ;
        clear x F

        % method 4: factorize method
        t = 0 ;
        k = 0 ;
        tic
        while (t < tmax)
            F = factorize (A, posdef) ;
            x = F\b ;
            k = k + 1 ;
            t = toc ;
        end
        Tfactor (i,4) = t / k ;
        err = max (err, norm (A*x-b,1) / (anorm + norm (x,1))) ;
        clear x F

        % method 5: inv method (ack!)
        t = 0 ;
        k = 0 ;
        tic
        while (t < tmax)
            S = inv (A) ;
            x = S*b ;               %#ok
            k = k + 1 ;
            t = toc ;
        end
        Tfactor (i,5) = t / k ;
        err = max (err, norm (A*x-b,1) / (anorm + norm (x,1))) ;
        clear x S

        tbest = min (Tfactor (i,:)) ;
        fprintf ('tbest %10.6f : backslash (%5.2f) ', tbest, ...
            Tfactor (i,1) / tbest);
        fprintf ('linsolve (%5.2f) ', Tfactor (i,2) / tbest) ;
        fprintf ('factorize1 (%5.2f) ', Tfactor (i,3) / tbest) ;
        fprintf ('factorize (%5.2f) ', Tfactor (i,4) / tbest) ;
        fprintf ('inv (%5.2f)\n',  Tfactor (i,5) / tbest) ;

    end

    %-----------------------------------------------------------------------
    % compare solve times
    %-----------------------------------------------------------------------

    fprintf ('\nCompare solve times:\n') ;
    for i = 1:ns
        n = nn (i) ;

        fprintf ('n %4d ', n) ;

        A = rand (n) ;
        if (posdef)
            A = A'*A + eye (n) ;
        end
        b = rand (n,1) ;
        anorm = norm (A,1) ;

        if (posdef)
            L = chol (A, 'lower') ;
        else
            [L,U,p] = lu (A,'vector') ;
        end

        S = inv (A) ;
        F = factorize  (A) ;
        F1 = factorize1 (A) ;

        if (posdef)

            % method 1: backslash (pos. definite case)
            t = 0 ;
            k = 0 ;
            tic
            while (t < tmax)
                x = L' \ (L\b) ;
                k = k + 1 ;
                t = toc ;
            end
            Tsolve (i,1) = t / k ;
            err = max (err, norm (A*x-b,1) / (anorm + norm (x,1))) ;
            clear x

            % method 2: linsolve (pos. definite case)
            t = 0 ;
            k = 0 ;
            tic
            while (t < tmax)
                x = linsolve (L, linsolve (L, b, lsolve), ltsolve) ;
                k = k + 1 ;
                t = toc ;
            end
            Tsolve (i,2) = t / k ;
            err = max (err, norm (A*x-b,1) / (anorm + norm (x,1))) ;
            clear x

        else

            % method 1: backslash (unsymmetric case)
            t = 0 ;
            k = 0 ;
            tic
            while (t < tmax)
                x = U \ (L \ (b (p))) ;
                k = k + 1 ;
                t = toc ;
            end
            Tsolve (i,1) = t / k ;
            err = max (err, norm (A*x-b,1) / (anorm + norm (x,1))) ;
            clear x

            % method 2: linsolve (unsymmetric case)
            t = 0 ;
            k = 0 ;
            tic
            while (t < tmax)
                x = linsolve (U, linsolve (L, b (p), lsolve), usolve) ;
                k = k + 1 ;
                t = toc ;
            end
            Tsolve (i,2) = t / k ;
            err = max (err, norm (A*x-b,1) / (anorm + norm (x,1))) ;
            clear x

        end

        % method 3: factorize1 object
        t = 0 ;
        k = 0 ;
        tic
        while (t < tmax)
            x = F1\b ;
            k = k + 1 ;
            t = toc ;
        end
        Tsolve (i,3) = t / k ;
        err = max (err, norm (A*x-b,1) / (anorm + norm (x,1))) ;
        clear x

        % method 4: factorize object
        t = 0 ;
        k = 0 ;
        tic
        while (t < tmax)
            x = F\b ;
            k = k + 1 ;
            t = toc ;
        end
        Tsolve (i,4) = t / k ;
        err = max (err, norm (A*x-b,1) / (anorm + norm (x,1))) ;
        clear x

        % method 5: "inv" method (ack!)
        t = 0 ;
        k = 0 ;
        tic
        while (t < tmax)
            x = S*b ;           %#ok
            k = k + 1 ;
            t = toc ;
        end
        Tsolve (i,5) = t / k ;
        err = max (err, norm (A*x-b,1) / (anorm + norm (x,1))) ;
        clear x

        tbest = min (Tsolve (i,:)) ;
        fprintf ('tbest %10.6f : backslash (%5.2f) ', tbest, ...
            Tsolve (i,1) / tbest);
        fprintf ('linsolve (%5.2f) ', Tsolve (i,2) / tbest) ;
        fprintf ('factorize1 (%5.2f) ', Tsolve (i,3) / tbest) ;
        fprintf ('factorize (%5.2f) ', Tsolve (i,4) / tbest) ;
        fprintf ('inv (%5.2f)\n',  Tsolve (i,5) / tbest) ;

        clear F F1 S L U p

    end

    % determine break-even values for inv
    fprintf ('\nBreak-even values K for inv vs the other methods\n') ;
    fprintf ('(# of solves must exceed K for inv(A)*b to be faster):\n') ;
    for i = 1:ns
        n = nn (i) ;
        s = zeros (4,1) ;
        for t = 1:4
            if (Tfactor (i,5) > Tfactor (i,t) && ...
                Tsolve (i,5) > Tsolve (i,t))
                % inv is always slower, for any K
                s (t) = inf ;
            elseif (Tfactor (i,5) < Tfactor (i,t) && ...
                Tsolve (i,5) < Tsolve (i,t))
                % inv is always faster, for any K
                s (t) = 1 ;
            else
                s (t) = (Tfactor (i,5) - Tfactor (i,t)) / ...
                         (Tsolve (i,t) - Tsolve (i,5));
            end
        end

        fprintf ('n %4d  # solves vs backslash %8.1f', n, max (1, s (1))) ;
        fprintf (' vs linsolve: %8.1f  ', max (1, s (2))) ;
        fprintf (' vs factorize1: %8.1f  ', max (1, s (3))) ;
        fprintf (' vs factorize: %8.1f\n', max (1, s (4))) ;
    end

end

%---------------------------------------------------------------------------
% compute the Schur complement, S = A-B*inv(D)*C
%---------------------------------------------------------------------------

fprintf ('\nSchur complement, S=A-B*inv(D)*C or A-B(D\\C),\n') ;
fprintf ('where A, B, C, and D are square and unsymmetric.\n') ;
fprintf ('"inverse" means S=A-B*inverse(D)*C, which does not actually\n') ;
fprintf ('use the inverse, but uses the factorization object instead.\n') ;

Tschur = zeros (ns,6) ;

for i = 1:ns
    n = nn (i) ;
    fprintf ('n %4d ', n) ;

    A = rand (n) ;
    B = rand (n) ;
    C = rand (n) ;
    D = rand (n) ;

    % method 1: backslash
    t = 0 ;
    k = 0 ;
    tic
    while (t < tmax)
        S = A - B*(D\C) ;                                               %#ok
        k = k + 1 ;
        t = toc ;
    end
    Tschur (i,1) = t / k ;
    clear S

    % method 2: linsolve
    t = 0 ;
    k = 0 ;
    tic
    while (t < tmax)
        S = A - B * linsolve (D,C) ;                                    %#ok
        k = k + 1 ;
        t = toc ;
    end
    Tschur (i,2) = t / k ;
    clear S

    % method 3: factorize1 object
    t = 0 ;
    k = 0 ;
    tic
    while (t < tmax)
        S = A - B*(factorize1(D)\C) ;                                   %#ok
        k = k + 1 ;
        t = toc ;
    end
    Tschur (i,3) = t / k ;
    clear F S

    % method 4: factorize object
    t = 0 ;
    k = 0 ;
    tic
    while (t < tmax)
        S = A - B*(factorize(D)\C) ;                                    %#ok
        k = k + 1 ;
        t = toc ;
    end
    Tschur (i,4) = t / k ;
    clear F S

    % method 5:
    t = 0 ;
    k = 0 ;
    tic
    while (t < tmax)
        S = A - B*inverse(D)*C ;                                        %#ok
        k = k + 1 ;
        t = toc ;
    end
    Tschur (i,5) = t / k ;
    clear S

    % method 6: "inv" method, using the explicit inverse (ack!)
    t = 0 ;
    k = 0 ;
    tic
    while (t < tmax)
        S = A - B*inv(D)*C ;                                            %#ok
        k = k + 1 ;
        t = toc ;
    end
    Tschur (i,6) = t / k ;
    clear S

    tbest = min (Tschur (i,:)) ;
    fprintf ('tbest %10.6f : backslash (%5.2f) ', tbest, ...
        Tschur (i,1) / tbest);
    fprintf ('linsolve (%5.2f) ', Tschur (i,2) / tbest) ;
    fprintf ('factorize1 (%5.2f) ', Tschur (i,3) / tbest) ;
    fprintf ('factorize (%5.2f) ', Tschur (i,4) / tbest) ;
    fprintf ('inverse (%5.2f) ', Tschur (i,5) / tbest) ;
    fprintf ('inv (%5.2f)\n',  Tschur (i,6) / tbest) ;

end

author: fieldtrip

repo: fieldtrip

save_path: github-repos/MATLAB/fieldtrip-fieldtrip


text:
function out = iszero(f)
%ISZERO   True for zero SINGFUN objects.
%   ISZERO(F) returns logical TRUE if the smooth part of F is zero and FALSE
%   otherwise.

% Copyright 2017 by The University of Oxford and The Chebfun Developers.
% See http://www.chebfun.org/ for Chebfun information.

% Check if the smooth part is zero:
out = iszero(f.smoothPart);

end

author: chebfun

repo: chebfun

save_path: github-repos/MATLAB/chebfun-chebfun


text:
function h=gridpcolor(ax,xs, ys, values, mask, name)
    % GRIDPCOLOR plots values, sampled at the intersection of xcenters and ycenters
    %
    % h=GRIDPCOLOR(ax,xs, ys, values, mask) where XS and YS are the same sized matrices of points.
    % and MASK is
    %
    % Pcolor typically uses the points as edges, and ignores the last values.
    %
    if isempty(ax)
        ax=gca;
    end
    if ~exist('name','var')
        name='';
    end
    name(name=='_')=' ';

    INCLUDENUMBERS=false;
    INCLUDECOORDS=false;

    if exist('mask','var')
        if islogical(values),values=double(values);end
        values(~mask)=nan;
    else
        mask=true(size(xs)+[1,1]);
    end

    [xs,ys, values]=centers2edges(xs,ys,values);
    ax.NextPlot='add';
    h=pcolor(ax,xs, ys, values);
    %if ~isempty('name')
    set(h,'DisplayName',name);
    %end
    if INCLUDENUMBERS
        for n=1:numel(xs)
            v=values(n);
            if ~isnan(v) && mask(n)
                if INCLUDECOORDS
                    text(ax,xs(n),ys(n),sprintf('(%.2f, %.2f)\n%s',xs(n),ys(n),num2str(v)));
                else
                    text(ax,xs(n),ys(mn),num2str(v));
                end
            end
        end
    end

author: CelsoReyes


text:
function ConvLDRvtoLDRi(filename, outputname, format)
%
%        ConvLDRvtoLDRi(filename, outputname, format)
%
%
%        Input:
%           -filename: video filename
%           -outputname: output name
%           -format: image file format
%
%        This function converts an LDR video into LDR images
%
%     Copyright (C) 2015  Francesco Banterle
%
%     This program is free software: you can redistribute it and/or modify
%     it under the terms of the GNU General Public License as published by
%     the Free Software Foundation, either version 3 of the License, or
%     (at your option) any later version.
%
%     This program is distributed in the hope that it will be useful,
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%     GNU General Public License for more details.
%
%     You should have received a copy of the GNU General Public License
%     along with this program.  If not, see <http://www.gnu.org/licenses/>.
%

ldrv = ldrvread(filename);

for i=1:ldrv.totalFrames
    [frame, ldrv] = ldrvGetFrame(ldrv, i);
    imwrite(frame, [outputname, sprintf('_%07d.', i), format]);
end

end

author: banterle


text:
function dramap_z(STYLE, bg_color, value_map)
    % drap a colormap of variance, S1 orientation onto topography
    %
    % requires:
    %   tmap : topography map
    %   tmapleg :
    %   gx, gy
    %   s1_north...s4_south

    assert(ismember(STYLE, {'dramap2_z','dramap_z','stress2'}));

    report_this_filefun();

    % STYLE simply allows this function to merge functionality of
    % two versions...
    %STYLE = "dramap2_z";
    %STYLE = "stress2";
    STYLE = "dramap_z";
    USE_SCALE_RULER = false; % SCALE_RULER code was commmented out in dramap_z and dramap_stress2.
                             % and didn't exist in dramap_z

    if ~has_mapping_toolbox()
        return
    end

    if ~exist('tmap', 'var')
        tmap = 0;
    end
    [xx, yy] = size(tmap);
    if xx*yy < 30
        errordlg('Please create a topomap first, using the options from the seismicity map window');
        return
    end
    if STYLE == "dramap2_z"
        projections = {... % friendly name      , official
            'Albers Equal-Area Conic'           , 'equaconic';...
            'Mercator Projection'               , 'mercator';...
            'Plate Carree Projection'           , 'pcarree'; ...
            'Lambert Conformal Conic Projection', 'lambert';...
            'Robinson Projection'               , 'robinson'};
        selz = menu('Choose a projection', projections{:,1});
        selected_proj = projections{selz, 2}; % was 'mapz(...)'
        mic_offset = 0.1;
    else
        selected_proj = 'eqaconic';
        mic_offset = 0;
    end

    dlgtitle ='Topo map input parameters';
    dstr(1).prompt = 'Longitude label spacing (degrees)';   dstr(1).value = 1;
    dstr(2).prompt = 'Latitude label spacing (degrees)';    dstr(2).value = 1;
    dstr(3).prompt = 'Topo data-aspect (steepness)';        dstr(3).value = 5;
    dstr(4).prompt = ' Minimum datavalue (cmin)';           dstr(4).value = min(value_map(:));
    dstr(5).prompt = ' Maximum datavalue cmap';             dstr(5).value = max(value_map(:));
    dstr(6).prompt = ' Sea Level (set values below this to 0. ex 0.01)';     dstr(6).value = -inf;

    [~, ~, dlo, dla, dda, mic, mac, sealevel] = smart_inputdlg(dlgtitle, dstr);

    % use this for setting water levels to one color
    %tmap(isnan(tmap)) = 1;

    tmap(tmap < sealevel) = 0;

    value_map(value_map < mic) = mic + mic_offset;
    value_map(value_map > mac) = mac;

    [lat, lon] = meshgrat(tmap, tmapleg);
    [X , Y]  = meshgrid(gx, gy);

    ren = interp2(X, Y, value_map, lon, lat);

    ren(isnan(ren)) = min(ren(:)) - 20;

    if STYLE == "dramap2_z"
        ren(tmap <= 1 & ren < mic) = nan;
    end

    %start figure
    fig = figure_w_normalized_uicontrolunits('pos', [50 100 800 600]);
    ax = gca;
    set(ax, 'NextPlot', 'add');
    axis off
    axesm('MapProjection', selected_proj, 'MapParallels', [],...
        'MapLatLimit', [s4_south s3_north], 'MapLonLimit', [s2_west s1_east])

    meshm(ren, tmapleg, size(tmap), tmap);

    daspectm('m', dda);
    tightmap
    view([0 90])
    camlight;
    lighting phong
    set(ax, 'projection', 'perspective');

    if STYLE == "stress2"
        % plot the bars
        plq = quiverm(newgri(:,2), newgri(:,1), -cos(ste(:,SA*2)*pi/180), sin(ste(:,SA*2)*pi/180),0.9);
        set(plq,'LineWidth', 0.4, 'Color', 'k', 'Markersize',0.1);
        set(gca,'NextPlot', 'add');

        delete(plq(2));
    end

    if STYLE == "dramap2_z" || STYLE == "stress2"
        if ~isempty(coastline)
            pl = plotm(coastline(:,2), coastline(:,1), 'k');
            set(pl, 'LineWidth', 0.5)
        end

        if ~isempty(ZG.maepi)
            pl = plotm(ZG.maepi.Y, ZG.maepi.X, 'hw');
            set(pl,'LineWidth', 1, 'MarkerSize', 14,...
                'MarkerFaceColor', 'w', 'MarkerEdgeColor', 'k')
        end
        if STYLE == "stress2"
            zdatam(handlem('allline'), max(tmap(:))) % keep line on surface
        end

        j = jet(64); % different from dramap2_z
        j = [ [ 0.8 0.8 0.8 ] ; j  ];
    else
        j = colormap;
        j = [ [ 0.9 0.9 0.9 ] ; j];
    end

    caxis([ mic * 0.99, mac * 1.01 ]);
    colormap(j);
    brighten(0.1);
    axis off;

    setm(ax,'mlabellocation', dlo)
    setm(ax,'meridianlabel', 'on')
    setm(ax,'plabellocation', dla)
    setm(ax,'parallellabel', 'on')

    if ~exist('bg_color', 'var') || bg_color == 'w' % white background
        fg = 'k';
        bg = 'w';
    else  % black background
        fg = 'w';
        bg = 'k';
    end

    set(fig, 'color', bg)
    setm(ax, 'ffacecolor', bg)
    setm(ax, 'fedgecolor', fg, 'flinewidth', 3);

    % change the labels if needed
    setm(ax,'Fontcolor', fg, 'Fontweight', 'bold', 'FontSize', 12, 'Labelunits', 'dm')

    h5 = colorbar;
    set(h5,'position',[0.8 0.35 0.01 0.3], 'TickDir', 'out', 'Ycolor', fg, 'Xcolor', fg,...
        'Fontweight', 'bold', 'FontSize', 12);
    set(fig, 'Inverthardcopy', 'off');

    if USE_SCALE_RULER
        scaleruler
        if STYLE == "dramap2_z"
            XLoc = -0.0133;
            YLoc = 0.639;
            MajorTick = 0:10:50;
            majorTickLength = 4;
        elseif STYLE == "stress2"
            XLoc = 12;
            YLoc = 40;
            MajorTick = 0:50:200;
            majorTickLength = 12;
        end

        setm(handlem('scaleruler1'), 'XLoc', XLoc, 'YLoc', YLoc, 'units', 'km')
        setm(handlem('scaleruler2'),'MajorTick', MajorTick,...
                'MinorTick', 0:10:25, 'TickDir', 'down',...
                'MajorTickLength', majorTickLength,...
                'MinorTickLength', 4)

        setm(handlem('scaleruler1'), 'RulerStyle', 'ruler')
        if STYLE == "dramap2_z"
            setm(handlem('scaleruler2'), 'RulerStyle', 'patches')
        end
        refresh
    end
end


text:
% EEG_MATCHCHANS  - find closest channels in a larger EEGLAB chanlocs structure
%                     to channels in a smaller chanlocs structure
% Usage:
%        >> [selchans,distances,selocs] = eeg_matchchans(BIGlocs,smalllocs,'noplot');
% Inputs:
%        BIGlocs    - larger (or equal-sized) EEG.chanlocs structure array
%        smalllocs  - smaller (or equal-sized) EEG.chanlocs structure array
% Optional inputs:
%        'noplot'   - [optional string 'noplot'] -> do not produce plots {default:
%                     produce illustrative plots of the BIG and small locations}
% Outputs:
%        selchans   - indices of BIGlocs channels closest to the smalllocs channels
%        distances  - vector of distances between the selected BIGlocs and smalllocs chans
%        selocs     - EEG.chanlocs structure array containing nearest BIGlocs channels
%                     to each smalllocs channel: 1, 2, 3,... n. This structure has
%                     two extra fields:
%                                    bigchan  - original channel index in BIGlocs
%                                    bigdist  - distance between bigchan and smalllocs chan
%                     ==> bigdist assumes both input locs have sph_radius 1.
%
% Author: Scott Makeig, SCCN/INC/UCSD, April 9, 2004

% Copyright (C) 2004 Scott Makeig, SCCN/INC/UCSD, smakeig@ucsd.edu
%
% This file is part of EEGLAB, see http://www.eeglab.org
% for the documentation and details.
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are met:
%
% 1. Redistributions of source code must retain the above copyright notice,
% this list of conditions and the following disclaimer.
%
% 2. Redistributions in binary form must reproduce the above copyright notice,
% this list of conditions and the following disclaimer in the documentation
% and/or other materials provided with the distribution.
%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
% THE POSSIBILITY OF SUCH DAMAGE.

% History: began Jan 27, 2004 as selectchans.m(?) -sm

function [selchans,dists,selocs] = eeg_matchchans(bglocs,ltlocs,noplot)

if nargin < 2
  help eeg_matchchans
  return
end
no_plot = 0; % yes|no flag
if nargin > 2 && strcmp(lower(noplot),'noplot')
  no_plot = 1;
end

if ~isstruct(bglocs) || ~isstruct(ltlocs)
   help eeg_matchchans
end

ltchans = length(ltlocs);
bgchans = length(bglocs);
if ltchans > bgchans
  fprintf('BIGlocs chans (%d) < smalllocs chans (%d)\n',bgchans,ltchans);
  return
end
selchans = zeros(ltchans,1);
dists    = zeros(ltchans,1);
bd       = zeros(bgchans,1);
%
%%%%%%%%%%%%%%%%% Compute the distances %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
fprintf('BIG  ltl  Dist\n');
for c=1:ltchans
   for C=1:bgchans
      if ~isempty(ltlocs(c).X) && ~isempty(bglocs(C).X)
        bd(C) = sqrt((ltlocs(c).X/ltlocs(c).sph_radius - bglocs(C).X/bglocs(C).sph_radius)^2 + ...
                    (ltlocs(c).Y/ltlocs(c).sph_radius - bglocs(C).Y/bglocs(C).sph_radius)^2 + ...
                    (ltlocs(c).Z/ltlocs(c).sph_radius - bglocs(C).Z/bglocs(C).sph_radius)^2);
      end
   end
   %
   %%%%%%%%%%%%%%%%% Find the nearest BIGlocs channel %%%%%%%%%%%%%%%%%%%%%%%
   %
   [bd ix] = sort(bd); % find smallest distance c <-> C
   bglocs(1).bigchan = [];
   k=1;
   while ~isempty(bglocs(ix(k)).bigchan) & k<=bgchans % avoid empty channels
     k=k+1;
   end
   if k>bgchans
     fprintf('No match found for smalllocs channel %d - error!?\n',c);
     return % give up - should not reach here!
   end
   while k<length(ix)
     if c>1 && sum(ismember(ix(k),selchans(1:c-1)))>0 % avoid chans already chosen
        k = k+1;
     else
        break
     end
   end
   if k==length(ix)
      fprintf('NO available nearby channel for littlechan %d - using %d\n',...
                  c,ix(k));
   end
   selchans(c) = ix(k); % note the nearest BIGlocs channel
   dists(c)    = bd(k); % note its distance
   bglocs(ix(k)).bigchan = selchans(c); % add this info to the output
   bglocs(ix(k)).bigdist = dists(c);
   fprintf('.bigchan %4d, c %4d, k %d, .bigdist  %3.2f\n',...
        bglocs(ix(k)).bigchan,c,k,bglocs(ix(k)).bigdist); % commandline printout
end; % c
selocs = bglocs(selchans); % return the selected BIGlocs struct array subset
%
%%%%%%%%%%%%%%%%% Plot the results %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
if ~no_plot
    figure;
    titlestring = sprintf('%d-channel subset closest to %d channel locations',ltchans,bgchans);
    tl=textsc(titlestring,'title');
    set(tl,'fontweight','bold');
    set(tl,'fontsize',15);
    sbplot(7,2,[3 13]);
    hist(dists,length(dists));
    title('Distances between corresponding channels');
    xlabel('Euclidian distance (sph. rad. 1)');
    ylabel('Number of channels');

    sbplot(7,5,[8,35]);
    topoplot(dists,selocs,'electrodes','numbers','style','both');
    title('Distances');
    clen = size(colormap,1);
    sbnull = sbplot(7,2,[10 12])
    cb=cbar;
    cbar(cb,[clen/2+1:clen]);
    set(sbnull,'visible','off')

    axcopy; % turn on axcopy
end

author: sccn

repo: eeglab

save_path: github-repos/MATLAB/sccn-eeglab


text:
% LFConvertToFloat - Helper function to convert light fields to floating-point representation
%
% Usage:
%     LF = LFConvertToFloat( LF, [Precision] )
%
% For float inputs, this converts between single and double without changes in scale. For integer
% inputs, the full input precision's range is mapped to a floating point range 0.0-1.0.
%
% Inputs:
%
%    LF :  Must be of type single, double, uint8, or uint16
%
% Optional Inputs:
%
%    Precision : one of 'single' or 'double', default 'single'
%
% Outputs:
%
%    LF : the converted LF
%
% User guide: LFToolbox.pdf
% See also: LFConvertToInt

% Copyright (c) 2013-2020 Donald G. Dansereau

function LF = LFConvertToFloat( LF, Precision )

Precision = LFDefaultVal('Precision', 'single');

OrigClass = class(LF);

if( strcmp( OrigClass, Precision ) )

	% already in the right precision, nothing to do

else
	IsInt = isinteger(LF);

	LF = cast(LF, Precision);

	if( IsInt )
		LF = LF ./ cast(intmax(OrigClass), Precision);
	end

end

repo: LFToolbox


text:
function [outdic,f,ci,ce,cs,g,ai,ae] = sqplab_simul(indic,x,lm,v)

switch indic
    case 0
    case 1
        outdic = 0;
    case 2
        [f,g] = sqplab_fun(x);
        [ci,ce,ai,ae] = sqplab_con(x);
         outdic = 0;
    case 3
        [f,g] = sqplab_fun(x);
        [ci,ce,ai,ae] = sqplab_con(x);
         outdic = 0;
    case 4
        [f,g] = sqplab_fun(x);
        [ci,ce,ai,ae] = sqplab_con(x);
     %   ci = -ci;
        ai = -ai;
        ai = reshape(ai,[],length(g));
        ae = reshape(ae,[],length(g));
        cs = [];
        outdic = 0;
end

author: zarathustr

repo: LibQPEP

save_path: github-repos/MATLAB/zarathustr-LibQPEP


text:
% This function produce short-time Fourier transform on the input signal
% according to the settings
% Author: Xiao Xiong
% Created: 2006
% Last modified: 24 Jun, 2006

function fft_x = sfft_multi(x,frame_size,frame_shift,FFT_length,window_type,do_DC_remove, useGPU, doDithering)

% x should be a TxN matrix, where T is the number of samples, and N is the
% number of channels.

if exist('do_DC_remove')==0 || length(do_DC_remove)==0
    do_DC_remove = 1;
end
if exist('useGPU')==0 || length(useGPU)==0
    useGPU = 0;
end

if exist('doDithering')==0 || length(doDithering)==0
   x = x + randn(size(x))/2^32;
end

% produce the hamming windowm
if exist('window_type')==0 || length(window_type)==0
    window = my_hamming(frame_size);
else
    switch window_type
        case 'hamming'
            window = my_hamming(frame_size);
        case 'hanning'
            window = hanning(frame_size);
        case 'rectangular'
            window = ones(frame_size,1);
    end
end

if do_DC_remove
    % DC offset removing
    x = DC_remove(gather(x),0.999);
    % pre-emphasis, boost the high frequency spectrum

    if 0
        % Method 2: Direct operation. In multichannel case, method 2 is
        % slower
        y = x(2:end,:) - 0.97*x(1:end-1,:);
        x = [x(1,:); y];
    else
        % Method 1: Call filter function. Too slow
        A    = [1 -0.97];
        x = filter(A,1,gather(x));
    end
end

if useGPU && ~IsInGPU(x)
    x = gpuArray(x);
end

if license('test', 'Signal_Toolbox')
    x_store = my_enframe(x, frame_size, frame_shift);
else
    for i=1:size(x,2)
        tmp = enframe(x(:,i), frame_size, frame_shift)';
        if i==1
            if useGPU
                x_store = gpuArray.zeros(size(tmp,1), size(tmp,2), size(x,2), class(gather(x)));
            else
                x_store = zeros(size(tmp,1), size(tmp,2), size(x,2), class(x));
            end
        end
        x_store(:,:,i) = tmp;
    end
    x_store = permute(x_store, [1 3 2]);
end

x_store = bsxfun(@times, x_store, window);

fft_x = fft(x_store,FFT_length);

N = FFT_length;
n = 0:N-1;
k = 0:N-1;
DFT_Trans = exp(-sqrt(-1)*2*pi*n(:)*k(:)'/N);
spec = DFT_Trans(1:N/2+1,1:frame_size) * squeeze(x_store(:,1,:));

end

author: singaxiong

repo: SignalGraph


text:
function [c,ceq] = heart(x)
% For nonlinear constraint demonstration.

c = (x(1)^2 + x(2)^2 - 1)^3 - x(1)^2*x(2)^3 ;
% c(2) = -x(1) ; % Half-heart
% ceq = x(1) - 1 ;
ceq = [] ;

author: Arrowstar

repo: ksptot

save_path: github-repos/MATLAB/Arrowstar-ksptot


text:
function npower3 = fac_lcm ( nprime, npower1, npower2 )

%*****************************************************************************80
%
%% FAC_LCM finds the LCM of two products of prime factors.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    17 April 2005
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, integer NPRIME, the index of the highest prime number
%    used in the representations.
%
%    Input, integer NPOWER1(NPRIME), the powers of primes
%    in the representation of the first quantity.
%
%    Input, integer NPOWER2(NPRIME), the powers of primes
%    in the representation of the second quantity.
%
%    Output, integer NPOWER3(NPRIME), the powers of primes
%    in the representation of the LCM.
%
  for i = 1 : nprime

    if ( npower1(i) < 0 )
      fprintf ( 1, '\n' );
      fprintf ( 1, 'FAC_LCM - Fatal error!\n' );
      fprintf ( 1, '  One of the powers is negative!\n' );
      error ( 'FAC_LCM - Fatal error!' );
    end

    if ( npower2(i) < 0 )
      fprintf ( 1, '\n' );
      fprintf ( 1, 'FAC_LCM - Fatal error!\n' );
      fprintf ( 1, '  One of the powers is negative!\n' );
      error ( 'FAC_LCM - Fatal error!' );
    end

    npower3(i) = max ( npower1(i), npower2(i) );

  end

  return
end


text:
function X=JumpDiffusionMerton(m,s,l,a,D,ts,J)

T=ts(end);
% simulate number of jumps;
N=poissrnd(l*T,J,1);

Jumps=[];
L=length(ts);
for j=1:J
    % simulate jump arrival time
    t=T*rand(N(j),1);
    t=sort(t);

    % simulate jump size
    S=a+D*randn(N(j),1);

    % put things together
    CumS=cumsum(S);
    for n=1:L
        Events=sum(t<=ts(n));
        Jumps_ts(n)=0;
        if Events
            Jumps_ts(n)=CumS(Events);
        end
    end

    Jumps=[Jumps
        Jumps_ts];
end
for l=1:L
    Dt=ts(l);
    if l>1
        Dt=ts(l)-ts(l-1);
    end
    D_Diff(:,l)=m*Dt + s*sqrt(Dt)*randn(J,1);
end

X=[zeros(J,1) cumsum(D_Diff,2)+Jumps];


text:
function value = i4vec_odd_all ( n, a )

%*****************************************************************************80
%
%% I4VEC_ODD_ALL is TRUE if all entries of an I4VEC are odd.
%
%  Discussion:
%
%    An I4VEC is a vector of I4's.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    17 April 2009
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, integer N, the number of entries in the vector.
%
%    Input, integer A(N), the vector.
%
%    Output, logical VALUE, TRUE if all entries are odd.
%
  value = all ( mod ( a(1:n), 2 ) == 1 );

  return
end


text:
function value = mm_header_check ( id, type, rep, field, symm )

%*****************************************************************************80
%
%% MM_HEADER_CHECK checks the header strings for a Matrix Market file.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    02 May 2004
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, character ( len = 14 ) ID, the Matrix Market identifier.
%    This value must be '%%MatrixMarket'.
%
%    Input, character ( len = 6 ) TYPE, the Matrix Market type.
%    This value must be 'matrix'.
%
%    Input, character ( len = 10 ) REP, the Matrix Market 'representation'
%    indicator.  Possible values include:
%    'coordinate'   (for sparse data)
%    'array'        (for dense data)
%    'elemental'    (to be added)
%
%    Input, character ( len = 7 ) FIELD, the Matrix Market 'field'.
%    Possible values include:
%    'real'
%    'double'
%    'complex'
%    'integer'
%    'pattern' (for REP = 'coordinate' only)
%
%    Input, character ( len = 19 ) SYMM, the Matrix Market symmetry.
%    Possible values include:
%    'symmetric'
%    'hermitian'
%    'skew-symmetric'
%    'general'
%
%    Output, logical VALUE, is TRUE if the header checks out.
%
  FALSE = 0;
  TRUE = 1;
%
%  Test the input qualifiers.
%
  if ( s_neqi ( id, '%%MatrixMarket' ) )
    fprintf ( 1, '\n' );
    fprintf ( 1, 'MM_HEADER_CHECK - Fatal error!\n' );
    fprintf ( 1, '  The value of ID was illegal:\n' );
    fprintf ( 1, '    "%s".\n', id );
    fprintf ( 1, '  Legal values are:\n' );
    fprintf ( 1, '    "%%MatrixMarket"\n' );
    value = FALSE;
    return;
  end

  if ( s_neqi ( type, 'matrix' ) )
    fprintf ( 1, '\n' );
    fprintf ( 1, 'MM_HEADER_CHECK - Fatal error!\n' );
    fprintf ( 1, '  The value of TYPE was illegal:\n' );
    fprintf ( 1, '    "%s".\n', type );
    fprintf ( 1, '  Legal values are:\n' );
    fprintf ( 1, '    "matrix"\n' );
    value = FALSE;
    return
  end

  if ( ...
    s_neqi ( rep, 'coordinate' ) & ...
    s_neqi ( rep, 'array'      ) )
    fprintf ( 1, '\n' );
    fprintf ( 1, 'MM_HEADER_CHECK - Fatal error!\n' );
    fprintf ( 1, '  The value of REP was illegal:\n' );
    fprintf ( 1, '    "%s".\n', rep );
    fprintf ( 1, '  Legal values are:\n' );
    fprintf ( 1, '    "array"\n' );
    fprintf ( 1, '    "coordinate"\n' );
    value = FALSE;
    return
  end

  if ( s_eqi ( rep, 'coordinate' ) )

    if ( ...
      s_neqi ( field, 'integer' ) & ...
      s_neqi ( field, 'real'    ) & ...
      s_neqi ( field, 'double'  ) & ...
      s_neqi ( field, 'complex' ) & ...
      s_neqi ( field, 'pattern' ) )
      fprintf ( 1, '\n' );
      fprintf ( 1, 'MM_HEADER_CHECK - Fatal error!\n' );
      fprintf ( 1, '  The value of FIELD was illegal:\n' );
      fprintf ( 1, '    "%s".\n', field );
      value = FALSE;
      return
    end

  elseif ( s_eqi ( rep, 'array' ) )

    if ( ...
      s_neqi ( field, 'integer' ) & ...
      s_neqi ( field, 'real'    ) & ...
      s_neqi ( field, 'double'  ) & ...
      s_neqi ( field, 'complex' ) )
      fprintf ( 1, '\n' );
      fprintf ( 1, 'MM_HEADER_CHECK - Fatal error!\n' );
      fprintf ( 1, '  The value of FIELD was illegal:\n' );
      fprintf ( 1, '    "%s".\n', field );
      value = FALSE;
      return
    end

  end

  if ( ...
    s_neqi ( symm, 'general'        ) & ...
    s_neqi ( symm, 'symmetric'      ) & ...
    s_neqi ( symm, 'hermitian'      ) & ...
    s_neqi ( symm, 'skew-symmetric' ) )
    fprintf ( 1, '\n' );
    fprintf ( 1, 'MM_HEADER_CHECK - Fatal error!\n' );
    fprintf ( 1, '  The value of SYMM was illegal:\n' );
    fprintf ( 1, '    "%s".\n', symm );
    value = FALSE;
    return
  end

  value = TRUE;

  return
end


text:
function roiSaveAllHdf5(view)
% saveAllROIsHdf5(view)
%
% Saves ROI to a file.
%
% davclark@white 03/17/06

if view.selectedROI==0
  myErrorDlg('No ROIs to save')
end

for r=1:length(view.ROIs)
  roiSaveHdf5(view,view.ROIs(r))
end

author: vistalab

repo: vistasoft

save_path: github-repos/MATLAB/vistalab-vistasoft


text:
function e = rmModelSearchFit_oneOvalGaussian(p,Y,Xv,Yv,stim,t)
% rmModelSearchFit_oneOvalGaussian - actual fit function of rmSearchFit
%
% error = rmModelSearchFit_oneOvalGaussian(p,Y,trends,Xgrid,YGrid,stimulusMatrix);
%
% Basic barebones fit of a single time-series. Error is returned in
% percentage: 100% is RSS of unfitted time-series. This way we can quantify
% the improvement of the fit independend of the variation in the raw
% time-series.
%
% 2006/06 SOD: wrote it.
% 2006/12 SOD: modifications for fmincon, this is litterally called >10000
% times so we cut every corner possible.

% make RF (taken from rfGaussian2d)
Xv = Xv - p(1);   % positive x0 moves center right
Yv = Yv - p(2);   % positive y0 moves center up

Xold = Xv;
Yold = Yv;
Xv = Xold .* cos(p(5)) - Yold .* sin(p(5));
Yv = Xold .* sin(p(5)) + Yold .* cos(p(5));

% make gaussian on current grid
RF = exp( -.5 * ((Yv ./ p(3)).^2 + (Xv ./ p(4)).^2));

% make prediction (taken from rfMakePrediction)
X = [stim*RF t];

% fit - inlining pinv
%b = pinv(X)*Y;
[U,S,V] = svd(X,0);
s = diag(S);
tol = numel(X) * eps(max(s));
r = sum(s > tol);
if (r == 0)
    pinvX = zeros(size(X'));
else
    s = diag(ones(r,1)./s(1:r));
    pinvX = V(:,1:r)*s*U(:,1:r)';
end
b = pinvX*Y;

% compute residual sum of squares (e)
% e = norm(Y - X*abs(b));
if b(1)>0,
    e = norm(Y - X*b);
else
    e = norm(Y).*(1+sum(abs(b(1))));
end
return;


text:
%%*********************************************************
%% convertcmpsdp: convert SDP with complex data into one
%%                with real data by converting
%%
%%  C - sum_{k=1}^m yk*Ak psd
%%  to
%%  [CR,-CI] - sum ykR*[AkR,-AkI] psd
%%  [CI, CR]           [AkI, AkR]
%%
%%  ykI = 0 for k = 1:m
%%
%% [bblk,AAt,CC,bb] = convertcmpsdp(blk,A,C,b);
%%
%%*********************************************************

function [bblk,AAt,CC,bb,iscmp] = convertcmpsdp(blk,A,C,b)

m = length(b);
pp = size(A,1);
if (pp ~= size(blk,1))
    error('blk and A not compatible');
end
numblk = size(blk,1);
iscmp = zeros(numblk,m+1);
for p = 1:size(blk,1)
    len = size(A(p),2);
    for k = 1:len
        if ~isempty(A{p,k})
            iscmp(p,k) = 1-isreal(A{p,k});
        end
    end
    iscmp(p,m+1) = 1-isreal(C{p});
end
iscmp = norm(iscmp,'fro');
%%
if (iscmp == 0)
    %% data is real
    bblk = blk; AAt = A; CC = C; bb = b;
    return;
end
%%
bb = real(b);
bblk = cell(size(blk,1),2);
for p = 1:size(blk,1)
    pblk = blk(p,:);
    if (size(pblk{2},1) > size(pblk{2},2))
        pblk{2} = pblk{2}';
    end
    if strcmp(pblk{1},'s')
        ss = [0,cumsum(pblk{2})];
        ss2 = [0,cumsum(2*pblk{2})];
        n = sum(pblk{2});
        n2 = sum(pblk{2}.*(pblk{2}+1))/2;
        AR = cell(1,m); Ctmp = sparse(2*n,2*n);
        if (size(A{p},1)==n2 && size(A{p},2)==m);
            Atype = 1;
        elseif (size(A(p),1)==1 && size(A(p),2)==1);
            Atype = 2;
        else
            error('convertcmp: At is not properly coded');
        end
        for k = 0:m
            if (k == 0)
                Ak = C{p};
            else
                if (Atype == 1)
                    Ak = smat(pblk,A{p}(:,k),1);
                elseif (Atype == 2)
                    Ak = A{p,k};
                end
            end
            Atmp = sparse(2*n,2*n);
            if (length(pblk{2}) == 1)
                tmp = [real(Ak),-imag(Ak);  imag(Ak), real(Ak)];
                if (k==0)
                    Ctmp = tmp;
                else
                    Atmp = tmp;
                end
            else
                for j = 1:length(pblk{2})
                    idx = ss(j)+1: ss(j+1);
                    Akj = Ak(idx,idx);
                    tmp = [real(Akj),-imag(Akj);  imag(Akj), real(Akj)];
                    idx2 = ss2(j)+1: ss2(j+1);
                    if (k==0)
                        Ctmp(idx2,idx2) = tmp; %#ok
                    else
                        Atmp(idx2,idx2) = tmp; %#ok
                    end
                end
            end
            if (k==0);
                CC{p,1} = Ctmp; %#ok
            else
                AR{k} = Atmp;
            end
        end
        bblk{p,1} = 's'; bblk{p,2} = 2*pblk{2};
        AAt(p,1) = svec(bblk(p,:),AR); %#ok
    elseif strcmp(pblk{1},'q');
        error('SOCP block with complex data is currently not allowed');
    elseif strcmp(pblk{1},'l');
        if isreal(A{p}) && isreal(C{p})
            bblk(p,:) = blk(p,:);
            AAt{p,1} = A{p}; CC{p,1} = C{p}; %#ok
        else
            error('data for linear block must be real');
        end
    elseif strcmp(pblk{1},'u');
        if isreal(A{p}) && isreal(C{p})
            bblk(p,:) = blk(p,:);
            AAt{p,1} = A{p}; CC{p,1} = C{p}; %#ok
        else
            error('data for unrestricted block must be real');
        end
    end
end
%%*********************************************************


text:
%kkthreshout 'Threshold Data Values Outside of the Specified Range'
% This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros kthreshout.pane file
%
% Parameters:
% InputFile: i 'Input ', required: 'Input file'
% OutputFile: o ' Output ', required: 'output file'
%
% Example: o = kkthreshout(i, {'i','';'o',''})
%
% Khoros helpfile follows below:
%
%  PROGRAM
% kthreshout - Threshold Data Values Outside of the Specified Range
%
%  DESCRIPTION
% The "Threshold Outside" operator generates a two-level output by
% thresholding the "Input" data object (i) outside the specified
% Lower and Upper Cutoff values (lc, uc).  Data values that are either
% less than the "Lower Cutoff Value" (lc), or greater than the \fIUpper
% Cutoff Value" (uc) are considered outside the threshold range, and are
% set to the first output value (fval).  Data values that are between, or
% equal to the cutoff values are within the threshold range, and are set to
% the second output value (tval).
%
% The following histogram defines the results of the thresholding operation.
% .KS
%
% \f(CW
%                                 |<-F->|<-T->|<-F->|
%                                 |     | :   | .   |
%                                 |    .:.:.  .:::  |
%                                 |:. .::::::.::::: |
%                                 |::::::::::::::::.|
%                                 ------|-----|------
%                                      lc     uc
%
%         F:  if value <  lc OR  value >  uc  output = fval
%         T:  if value >= lc AND value <= uc  output = tval
% "
%
% .KE
% P "Data Type" 5
% .cI $DATAMANIP/repos/shared/man/sections/value_type_1input
%
%  "Map Data" 5
% .cI $DATAMANIP/repos/shared/man/sections/map_1input
%
%  "Validity Mask" 5
% .cI $DATAMANIP/repos/shared/man/sections/mask_1input
%
%  "Explicit Location and Time Data" 5
% .cI $DATAMANIP/repos/shared/man/sections/loc_and_time_1input
%
%  "Failure Modes"
% .cI $DATAMANIP/repos/shared/man/sections/fail_1input
%
% Executing "Threshold Outside" runs the program \fIkclip\fP with the -thresh
% option set to TRUE (-thresh 1).
%
%
%
%  EXAMPLES
%
%  "SEE ALSO"
% DATAMANIP::kthreshabove, DATAMANIP::kthreshbelow, DATAMANIP::kthreshin,
% DATAMANIP::kmegathresh, DATAMANIP::kclip
%
%  RESTRICTIONS
%
%  REFERENCES
%
%  COPYRIGHT
% Copyright (C) 1993 - 1997, Khoral Research, Inc. ("KRI")  All rights reserved.
%

function varargout = kkthreshout(varargin)
if nargin ==0
  Inputs={};arglist={'',''};
elseif nargin ==1
  Inputs=varargin{1};arglist={'',''};
elseif nargin ==2
  Inputs=varargin{1}; arglist=varargin{2};
else error('Usage: [out1,..] = kkthreshout(Inputs,arglist).');
end
if size(arglist,2)~=2
  error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
 end
narglist={'i', '__input';'o', '__output'};
maxval={0,0};
minval={0,0};
istoggle=[0,0];
was_set=istoggle * 0;
paramtype={'InputFile','OutputFile'};
% identify the input arrays and assign them to the arguments as stated by the user
if ~iscell(Inputs)
Inputs = {Inputs};
end
NumReqOutputs=1; nextinput=1; nextoutput=1;
  for ii=1:size(arglist,1)
  wasmatched=0;
  for jj=1:size(narglist,1)
   if strcmp(arglist{ii,1},narglist{jj,1})  % a given argument was matched to the possible arguments
     wasmatched = 1;
     was_set(jj) = 1;
     if strcmp(narglist{jj,2}, '__input')
      if (nextinput > length(Inputs))
        error(['Input ' narglist{jj,1} ' has no corresponding input!']);
      end
      narglist{jj,2} = 'OK_in';
      nextinput = nextinput + 1;
     elseif strcmp(narglist{jj,2}, '__output')
      if (nextoutput > nargout)
        error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
      end
      if (isempty(arglist{ii,2}))
        narglist{jj,2} = 'OK_out';
      else
        narglist{jj,2} = arglist{ii,2};
      end

      nextoutput = nextoutput + 1;
      if (minval{jj} == 0)
         NumReqOutputs = NumReqOutputs - 1;
      end
     elseif isstr(arglist{ii,2})
      narglist{jj,2} = arglist{ii,2};
     else
        if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
            error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
        end
        if (minval{jj} ~= 0 | maxval{jj} ~= 0)
          if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
            error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
          elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
            error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
          elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
            error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
          elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
            error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
          elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
            error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
          elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
            error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
          end
        end
     end
     if ~strcmp(narglist{jj,2},'OK_out') &  ~strcmp(narglist{jj,2},'OK_in')
       narglist{jj,2} = arglist{ii,2};
     end
   end
   end
   if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
        error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
   end
end
% match the remaining inputs/outputs to the unused arguments and test for missing required inputs
 for jj=1:size(narglist,1)
     if  strcmp(paramtype{jj}, 'Toggle')
        if (narglist{jj,2} ==0)
          narglist{jj,1} = '';
        end;
        narglist{jj,2} = '';
     end;
     if  ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
          narglist{jj,1} = '';
          narglist{jj,2} = '';
     end;
     if strcmp(narglist{jj,2}, '__input')
      if (minval{jj} == 0)  % meaning this input is required
        if (nextinput > size(Inputs))
           error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
        else
          narglist{jj,2} = 'OK_in';
          nextinput = nextinput + 1;
        end
      else  % this is an optional input
        if (nextinput <= length(Inputs))
          narglist{jj,2} = 'OK_in';
          nextinput = nextinput + 1;
        else
          narglist{jj,1} = '';
          narglist{jj,2} = '';
        end;
      end;
     else
     if strcmp(narglist{jj,2}, '__output')
      if (minval{jj} == 0) % this is a required output
        if (nextoutput > nargout & nargout > 1)
           error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
        else
          narglist{jj,2} = 'OK_out';
          nextoutput = nextoutput + 1;
          NumReqOutputs = NumReqOutputs-1;
        end
      else % this is an optional output
        if (nargout - nextoutput >= NumReqOutputs)
          narglist{jj,2} = 'OK_out';
          nextoutput = nextoutput + 1;
        else
          narglist{jj,1} = '';
          narglist{jj,2} = '';
        end;
      end
     end
  end
end
if nargout
   varargout = cell(1,nargout);
else
  varargout = cell(1,1);
end
global KhorosRoot
if exist('KhorosRoot') && ~isempty(KhorosRoot)
w=['"' KhorosRoot];
else
if ispc
  w='"C:\Program Files\dip\khorosBin\';
else
[s,w] = system('which cantata');
w=['"' w(1:end-8)];
end
end
[varargout{:}]=callKhoros([w 'kclip"  -thresh'],Inputs,narglist);

author: aludnam

repo: MATLAB

save_path: github-repos/MATLAB/aludnam-MATLAB


text:
% eeg_eventtypes()  - return a list of event or urevent types in a dataset and
%                     the respective number of events of each type. Ouput event
%                     or urevent types are sorted in reverse order of their number.
%                     If no outputs, print this list on the commandline instead.
%
% WARNING: this function returns the wrong frequency of events (see bug 519)
%          this is a deprecated function.
%
% Usage:
%        >> [types,numbers] = eeg_eventtypes(EEG);
%        >> [types,numbers] = eeg_eventtypes(EEG,types);
%        >> [types,numbers] = eeg_eventtypes(EEG,'urevents',types);
% Inputs:
%        EEG        - EEGLAB dataset structure
%        'urevents' - return event information for the EEG.urevent structure
%        types      - {cell array} of event types to return or print.
% Outputs:
%        types      - cell array of event type strings
%        numbers    - vector giving the numbers of each event type in the data
%
% Note:  Numeric (ur)event types are converted to strings, so, for example,
%        types {13} and {'13'} are not distinguished.
%
% Examples:
%           >> eeg_eventtypes(EEG);       % print histogram of event types
%           >> eeg_eventtypes(EEG,'urevent');  % print hist. of urevent types
%           >> eeg_eventtypes(EEG,{'rt'});% print number of 'rt' events
%           >> eeg_eventtypes(EEG,'urevent',{'rt','break'});
%                                         % print numbers of 'rt' and 'break'
%                                         % type urevents
%
% Author: Scott Makeig, SCCN/INC/UCSD, April 28, 2004-

% Copyright (C) 2004 Scott Makeig, SCCN/INC/UCSD, smakeig@ucsd.edu
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
%
%
% event types can be numbers, Stefan Debener, 05/12/2006,
% added 2nd and 3rd args, sorted outputs by number, Scott Makeig, 09/12/06

function [types,numbers] = eeg_eventtypes(EEG,arg2,arg3)

if nargin< 1
   help eeg_eventtypes
   return
end
if ~isstruct(EEG)
   error('EEG argument must be a dataset structure')
end

if ~isfield(EEG,'event')
   error('EEG.event field not found');
end

UREVENTS = 0; % flag returning infor for urevents instead of events
typelist = [];
if nargin>1
   if ischar(arg2)
       if strcmp(arg2,'urevent') | strcmp(arg2,'urevents')
            UREVENTS = 1; % change flag
       else
            error('second argument string not understood')
       end
       if nargin>2
            if iscell(arg3)
                  typelist = arg3;
            end
       end
   elseif iscell(arg2)
       typelist = arg2;
   end
end
if ~isempty(typelist)     % cast to cell array of strings
   for k=1:length(typelist)
       if isnumeric(typelist{k})
          typelist{k} = num2str(typelist{k});
       end
   end
end

if ~UREVENTS
   nevents = length(EEG.event);
   alltypes = cell(nevents,1);
   for k=1:nevents
       if isnumeric(EEG.event(k).type)
          alltypes{k} = num2str(EEG.event(k).type);
       else
          alltypes{k} = EEG.event(k).type;
       end
   end
else
   nevents = length(EEG.urevent);
   alltypes = cell(nevents,1);
   for k=1:nevents
       if isnumeric(EEG.urevent(k).type)
          alltypes{k} = num2str(EEG.urevent(k).type);
       else
          alltypes{k} = EEG.urevent(k).type;
       end
   end
end

[types i j] = unique(alltypes);

istypes = 1:length(types);
notistypes = [];
if ~isempty(typelist)
  notistypes = ismember(typelist,types);
  istypes = ismember(types,typelist(find(notistypes==1))); % types in typelist?
  notistypes = typelist(find(notistypes==0));
end

types(~istypes) = []; % restrict types to typelist

ntypes = length(types);
numbers = zeros(ntypes + length(notistypes),1);
for k=1:ntypes
  numbers(k) = length(find(j==k));
end
types = [types(:); notistypes(:)]; % concatenate the types not found
ntypes = length(types);
for j = 1:length(notistypes)
   numbers(k+j) = 0;
end

% sort types in reverse order of event numbers
[numbers nsort] = sort(numbers);
numbers = numbers(end:-1:1);
types = types(nsort(end:-1:1));

%
% print output on commandline %%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
if nargout < 1
  fprintf('\n');
  if UREVENTS
    fprintf('EEG urevent types:\n\n')
  else
    fprintf('EEG event types:\n\n')
  end

  maxx = 0;
  for k=1:ntypes
    x = length(types{k});
    if x > maxx
        maxx = x; % find max type name length
    end
  end
  for k=1:ntypes
    fprintf('  %s',types{k});
    for j=length(types{k})+1:maxx+4
       fprintf(' ');
    end
    fprintf('%d\n',numbers(k));
 end
 fprintf('\n');
 clear types % no return variables
end

author: PatternRecognition

repo: OpenBMI


text:
classdef FullInnerMeshCreator_Matlab < InnerMeshExporter

    methods (Access = public)

        function obj = FullInnerMeshCreator_Matlab(cParams)
            obj.init(cParams)

        end

        function m = export(obj)
            coordInner     = obj.unfittedMesh.innerMesh.mesh.coord;
            connecInner    = obj.unfittedMesh.innerMesh.mesh.connec;
            coordCutInner  = obj.unfittedMesh.innerCutMesh.mesh.coord;
            connecCutInner = obj.unfittedMesh.innerCutMesh.mesh.connec;
            ncoord = size(coordInner,1);
            connecCutInner = connecCutInner + ncoord;
            s.coord  = [coordInner;  coordCutInner];
            s.connec = [connecInner; connecCutInner];
            m = Mesh(s);
        end

    end

    methods (Access = private)

        function init(obj,cParams)
            obj.unfittedMesh  = cParams.unfittedMesh;
        end

    end

end

author: SwanLab

repo: Swan

save_path: github-repos/MATLAB/SwanLab-Swan


text:
%compute dcentralheadang
function [data,units]=compute_dcentralheadang(trx,n)

larvae=trx.exp2flies{n};
numlarvae=numel(larvae);
%absdtailheadang=cell(1,numlarvae);
dcentralheadang=cell(1,numlarvae);
for i=1:numlarvae
    larva=larvae(i);
%     absdtailheadang{1,i}=real(acos(cos(tailheadang{1,i}(1:end-1)).*cos(tailheadang{1,i}(2:end))+sin(tailheadang{1,i}(1:end-1)).*sin(tailheadang{1,i}(2:end))))./trx(i).dt;
%     temp=tailheadang{1,i}-pi/2;
%     cosperp=sign(cos(temp(1:end-1)).*cos(tailheadang{1,i}(2:end))+sin(temp(1:end-1)).*sin(tailheadang{1,i}(2:end)));
%     temp2=bsxfun(@times,absdtailheadang{1,i},cosperp);
    dcentralheadang{1,i}=modrange(diff(trx(larva).centralheadang),-pi,pi)./trx(larva).dt;
    % KB: this angle distance didn't make sense to me, changed to one that
    % made sense to me
    %dcentralheadang{1,i}=(mod1(trx(larva).centralheadang(2:end)-trx(larva).centralheadang(1:end-1),pi)-pi)./trx(larva).dt;
end

units=parseunits('rad/s');
data=dcentralheadang;

author: kristinbranson

repo: JAABA


text:
clear; close all; clc;
%% easiest example of curl: a stick on a stream

[x,y]=meshgrid(0:1/10:1.5);
u=y;
v=zeros(size(x));

figure;
quiver(x,y,u,v);
% grid on;
axis([0 1 0 1])

%% easy example for curl: Vortex
figure('position',[542, 137, 750, 627]);
U_i = 10;% free stream velocity
C = 1000/(2*pi);% vortex strength
meshfactor = 10;
[x,y] = meshgrid(-U_i:U_i/meshfactor:U_i);

x1 = 0;
y1 = 0;
u1 = U_i - C*(y-y1)./(2*((x-x1).^2 + (y-y1).^2)); %%define the velocity component in the x
v1 = C*(x-x1)./(2*((x-x1).^2 + (y-y1).^2)); %%define the velocity component in the y

x2 = 4;
y2 = 5;
u2 = U_i + C*(y-y2)./(2*((x-x2).^2 + (y-y2).^2)); %%define the velocity component in the x
v2 = -C*(x-x2)./(2*((x-x2).^2 + (y-y2).^2)); %%define the velocity component in the y

u = u1+u2;
v = v1+v2;

[r,c]=find(isnan(u));

for i = 1:2
    u(r(i), c(i))=mean([u(r(i)-1,c(i)),u(r(i)+1,c(i))]);
    v(r(i), c(i))=mean([v(r(i)-1,c(i)),v(r(i)+1,c(i))]);
end

quiver(x,y,u,v)
xlim([-U_i, U_i])
ylim([-U_i, U_i])
set(gcf,'position',[542 137 750 627])

%
set(gcf,'color','w');
hold on;
[verts,averts] = streamslice(x,y,u,v);
sl = streamline([verts averts]);

iverts = interpstreamspeed(x,y,u,v,verts,0.01);
streamparticles(iverts,100,'Animate',15,'FrameRate',40,'Markersize',5)

%% Vortex represented with curl

figure;
ccurl=curl(x,y,u,v);
pcolor(x,y,ccurl);
hold on
shading interp
colormap(jet);

quiver(x,y,u,v);
xlim([-U_i, U_i])
ylim([-U_i, U_i])
set(gcf,'position',[542 137 750 627])

%% ex: wind
k = 4;
load wind
x = x(:,:,k);
y = y(:,:,k);
u = u(:,:,k);
v = v(:,:,k);
figure;
cav = curl(x,y,u,v);
pcolor(x,y,cav);
shading interp
hold on
quiver(x,y,u,v,'y','color','k');
hold off
colormap('jet');

author: angeloyeo

repo: gongdols

save_path: github-repos/MATLAB/angeloyeo-gongdols