text:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Spherical Harmonic Modeling and Analysis Toolkit (SPHARM-MAT) is a 3D
% shape modeling and analysis toolkit.
% It is a software package developed at Shenlab in Center for Neuroimaging,
% Indiana University (SpharmMat@gmail.com, http://www.iupui.edu/~shenlab/)
% It is available to the scientific community as copyright freeware
% under the terms of the GNU General Public Licence.
%
% Copyright 2009, 2010, ShenLab, Center for Neuroimaging, Indiana University
%
% This file is part of SPHARM-MAT.
%
% SPHARM-MAT 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.
%
% SPHARM-MAT 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 SPHARM-MAT. If not, see <http://www.gnu.org/licenses/>.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function performTstat(confs, objs1, objs2, cpath)

% Load an atlas. If atlas name is empty, create an atlas using objs1
if exist(confs.Atlas,'file')
    load(confs.Atlas);
    atlas_fvec = fvec;
else
    conf.OutputName = 'atlas.mat';
    conf.OutDirectory = confs.OutDirectory;
    conf.SampleMesh = confs.SampleMesh;

    atlas_fvec = averageObjs(conf, objs1);
end

groupID=confs.GroupIDs;

% Load a sampling mesh
switch deblank(char(confs.SampleMesh))
%     case 'quad32'
%         load('ParamMeshes/R32_quad.mat');
%     case 'quad64'
%         load('ParamMeshes/R64_quad.mat');
%     case 'quad128'
%         load('ParamMeshes/R128_quad.mat');
%     case 'quad256'
%         load('ParamMeshes/R256_quad.mat');
%     case 'quad512'
%         load('ParamMeshes/R512_quad.mat');
    case 'icosa1'
        load(fullfile(cpath,'ParamMeshes/L1_icosa.mat'));
    case 'icosa2'
        load(fullfile(cpath,'ParamMeshes/L2_icosa.mat'));
    case 'icosa3'
        load(fullfile(cpath,'ParamMeshes/L3_icosa.mat'));
    case 'icosa4'
        load(fullfile(cpath,'ParamMeshes/L4_icosa.mat'));
    case 'icosa5'
        load(fullfile(cpath,'ParamMeshes/L5_icosa.mat'));
    case 'icosa6'
        load(fullfile(cpath,'ParamMeshes/L6_icosa.mat'));
end

% Reconstruct the atlas using the loaded sampling mesh
max_d = sqrt(size(atlas_fvec,1))-1;
dg = [0 max_d];
Z = calculate_SPHARM_basis(sph_verts, max_d);
lb = 1;
ub = (max_d+1)^2;
atlas_vertices = real(Z(:,lb:ub)*atlas_fvec(lb:ub,:));

% create neighborhood
nbr = get_nbr(faces,sph_verts);

% get vertex normals
vtnorm = get_vertexnormals(atlas_vertices,faces);

% Extract signal from all individuals
[defms, sgdfms, sgnrms, sgpcas, sgflds, grInfo]=extractSignals(atlas_vertices, faces, Z, max_d, vtnorm, objs1, objs2)

% Smoothe signals
FWHM = confs.Smoothing_FWHM;

for i=1:length(sgdfms)
    sgdfms{i} = performHKsmooth(sgdfms{i},atlas_vertices,faces,nbr,FWHM);
    sgnrms{i} = performHKsmooth(sgnrms{i},atlas_vertices,faces,nbr,FWHM);
    sgflds{i} = performHKsmooth(sgflds{i},atlas_vertices,faces,nbr,FWHM);
    sgpcas{i} = performHKsmooth(sgpcas{i},atlas_vertices,faces,nbr,FWHM);
end

% Perform t-test
signal = deblank(char(confs.Signal));
evar = deblank(char(confs.EqualVariance));
if strcmp(upper(evar),'YES')
    samevar = 1;
else
    samevar = 0;
end

c1sbs = find(grInfo == 1);
c2sbs = find(grInfo == 2);

switch lower(signal)
    case 'vl_defm_org'
        [tstats,pvalue] = grp_ttest(c1sbs,c2sbs,sgdfms,samevar)
    case 'vl_defm_nrm'
        [tstats,pvalue] = grp_ttest(c1sbs,c2sbs,sgnrms,samevar)
    case 'vl_defm_pca'
        [tstats,pvalue] = grp_ttest(c1sbs,c2sbs,sgpcas,samevar)
    case 'vl_defm_fld'
        [tstats,pvalue] = grp_ttest(c1sbs,c2sbs,sgflds,samevar)
end

% Save results
IDS = strrep(confs.GroupIDs,',','v');
IDS = strrep(IDS,' ','v');

new_name = [confs.OutDirectory '/' confs.OutputName];
if exist(new_name,'file')
    prompt = {'Enter new filename:'};
    dlg_title = 'New File Name';
    num_lines = 1;
    def = {new_name};
    answer = inputdlg(prompt,dlg_title,num_lines,def);
    new_name = answer{1};
end

save(new_name, 'sph_verts', 'faces', 'atlas_vertices', 'vtnorm','grInfo','groupID','signal','tstats','pvalue','FWHM');

return;

%
% find t and p
%

function  [tstat,pvalue] = grp_ttest(c1sbs,c2sbs,sigs,samevar); % CN VS MCI

for i=1:length(c1sbs)
    id = c1sbs(i);
    ndefms1(:,:,i) = sigs{id};
end
for i=1:length(c2sbs)
    id = c2sbs(i);
    ndefms2(:,:,i) = sigs{id};
end

%  the standard deviations are unknown and not assumed equal.
d = size(ndefms1);
for i=1:d(1)
    for j=1:d(2)
        if samevar
            [h,significance,ci,stats] = ttest2(ndefms1(i,j,:),ndefms2(i,j,:),0.05);
            pvalue(i,j) = significance; tstat(i,j) = stats.tstat;
        else
            [tstat(i,j),pvalue(i,j)] = ttest2_var2(ndefms1(i,j,:),ndefms2(i,j,:));
        end
    end
end

return;

%
% two-sample t-test for equal means, variances not assumed equal.
%

function [t,p] = ttest2_var2(xs,ys)

mu1 = mean(xs); mu2 = mean(ys);
var1 = var(xs); var2 = var(ys);
n1 = length(xs); n2 = length(ys);

% t statistic
t = (mu1 - mu2)/sqrt(var1/n1 + var2/n2);
% degree of freedom
v = (var1/n1 + var2/n2)^2/((var1/n1)^2/(n1-1) + (var2/n2)^2/(n2-1));

% tail == 1
p = 1 - tcdf(t,v);
% adjust for tail == 0
p = 2 * min(p,1-p);

return;

%
% get nbr
%

function nbr = get_nbr(tri,coord)

n_points = size(coord,1);
n_tri = size(tri,1);

% compute the maximum degree of node
degree=zeros(n_points,1);
for j=1:n_tri
degree(tri(j,:))=degree(tri(j,:))+1;
end
max_degree=max(degree);

% find out the 1st neighbor nodes
nbr=zeros(n_points,max_degree);
for i_tri=1:n_tri
    for j=1:3
        cur_point = tri(i_tri,j);
        for k=1:3
            if (j ~= k)
                nbr_point= tri(i_tri,k);
                if find(nbr(cur_point,:)==nbr_point)
                    ;
                else
                    n_nbr = min(find(nbr(cur_point,:) == 0));
                    nbr(cur_point,n_nbr) = nbr_point;
                end;
            end;
        end;
    end;
end;

return;

author: vigente

repo: gerardus

save_path: github-repos/MATLAB/vigente-gerardus


text:
function lobatto_polynomial_derivative_test ( )

%*****************************************************************************80
%
%% LOBATTO_POLYNOMIAL_DERIVATIVE_TEST tests LOBATTO_POLYNOMIAL_DERIVATIVE.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    18 November 2014
%
%  Author:
%
%    John Burkardt
%
  m = 1;

  fprintf ( 1, '\n' );
  fprintf ( 1, 'LOBATTO_POLYNOMIAL_DERIVATIVE_TEST:\n' );
  fprintf ( 1, '  LOBATTO_POLYNOMIAL_DERIVATIVES stores derivatives of\n' );
  fprintf ( 1, '  the completed Lobatto polynomial L(n,x).\n' );
  fprintf ( 1, '  LOBATTO_POLYNOMIAL_DERIVATIVE evaluates the completed Lobatto polynomial.\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '                                       Tabulated                 Computed\n' );
  fprintf ( 1, '     N        X                        L''(N,X)                   L''(N,X)       Error\n' );
  fprintf ( 1, '\n' );

  n_data = 0;

  while ( 1 )

    [ n_data, n, x, fx1 ] = lobatto_polynomial_derivatives ( n_data );

    if ( n_data == 0 )
      break
    end

    lp = lobatto_polynomial_derivative ( m, n, x );
    fx2 = lp(1,n);

    e = fx1 - fx2;

    fprintf ( 1, '  %4d  %12f  %24g  %24g  %8g\n', n, x, fx1, fx2, e );

  end

  return
end

author: johannesgerer

repo: jburkardt-m


text:
%% Copyright (C) 2014-2022 Colin B. Macdonald
%%
%% This file is part of OctSymPy.
%%
%% OctSymPy 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 software 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 software; see the file COPYING.
%% If not, see <http://www.gnu.org/licenses/>.

%% -*- texinfo -*-
%% @documentencoding UTF-8
%% @defmethod @@sym floor (@var{x})
%% Symbolic floor function.
%%
%% Example:
%% @example
%% @group
%% syms x
%% y = floor (x)
%%   @result{} y = (sym) ⌊x⌋
%% @end group
%% @end example
%%
%% Note: this file is autogenerated: if you want to edit it, you might
%% want to make changes to 'generate_functions.py' instead.
%%
%% @end defmethod

function y = floor(x)
  if (nargin ~= 1)
    print_usage ();
  end
  y = elementwise_op ('floor', x);
end

%!error floor (sym(1), 2)
%!assert (isequaln (floor (sym(nan)), sym(nan)))

%!shared x, d
%! d = 1;
%! x = sym('1');

%!test
%! f1 = floor(x);
%! f2 = floor(d);
%! assert( abs(double(f1) - f2) < 1e-15 )

%!test
%! D = [d d; d d];
%! A = [x x; x x];
%! f1 = floor(A);
%! f2 = floor(D);
%! assert( all(all( abs(double(f1) - f2) < 1e-15 )))

%!test
%! % round trip
%! y = sym('y');
%! A = floor (d);
%! f = floor (y);
%! h = function_handle (f);
%! B = h (d);
%! assert (A, B, -eps)

repo: octsympy


text:
function rect = boxToRect(box)
%BOXTORECT Convert box data to rectangle data
%
%   RECT = boxToRect(BOX)
%   Converts from boxrepresentation to rectangle representation.
%   BOX is given by [XMIN XMAX YMIN YMAX].
%   RECT is given by [X0 Y0 WIDTH HEIGHT], with WIDTH and HEIGHT > 0
%
%   See also
%   boxes2d, boxToPolygon, drawBox
%

% ------
% Author: David Legland
% e-mail: david.legland@inra.fr
% Created: 2012-08-23,    using Matlab 7.9.0.529 (R2009b)
% Copyright 2012 INRA - Cepia Software Platform.

rect = [box(:,1) box(:,3) box(:,2)-box(:,1) box(:,4)-box(:,3)];

author: rpng

repo: lips

save_path: github-repos/MATLAB/rpng-lips


text:
function wt = comp_wpfbtscale(wt,interscaling)
%COMP_WPFBTSCALE Scale filters in the filterbank tree

% Here we handle scaling of intermediate outputs in the tree
if ~strcmpi(interscaling,'intnoscale')
    if strcmp('intscale',interscaling)
        interscalingfac = 1/2;
    elseif strcmp('intsqrt',interscaling)
        interscalingfac = 1/sqrt(2);
    end

    wtPath = nodeBForder(0,wt);
    rangeLoc = nodesLocOutRange(wtPath,wt);
    wtNodes = wt.nodes(wtPath);

    for ii=1:numel(wtPath)
          range = 1:numel(wtNodes{ii}.h);
          % Remove the outputs which are terminal
          range(rangeLoc{ii}) = [];
          wtNodes{ii}.h(range) = ...
             cellfun(@(hEl) setfield(hEl,'h',hEl.h*interscalingfac),...
                     wtNodes{ii}.h(range),...
                     'UniformOutput',0);

          wtNodes{ii}.g(range) = ...
             cellfun(@(hEl) setfield(hEl,'h',hEl.h*interscalingfac),...
                     wtNodes{ii}.g(range),...
                     'UniformOutput',0);
    end
    % Write the scaled ones back
    wt.nodes(wtPath) = wtNodes;
end

author: ltfat

repo: ltfat

save_path: github-repos/MATLAB/ltfat-ltfat


text:
function p2c = MoritoOrder(p2c)
% adjusts ordering of variants according to Morito convention
%
% Syntax
%
%   p2c.variantMap = MoritoOrder(p2c)
%
%   p2cV = variants(p2c)
%
% Input
%  p2c - parent to child orientation relationship, @orientation
%
% Output
%  variantMap - reordering of the default MTEX variants
%

% default variant ordering
p2c.opt.variantMap = [];
p2cV = p2c.variants;

% set up planes and directions
% TODO: make this work for OR other than Kurdjumov Sachs
[nParent,nChild,dParent,dChild] = round2Miller(p2cV(1));

csParent = p2cV.CS;
csChild = p2cV.SS;

if angle(nParent,Miller({1 1 1},csParent)) < 5*degree
  nParent = Miller({1 1 1},{1 -1 1},{-1 1 1},{1 1 -1},csParent);
else
  nParent = nParent.symmetrise;
end

if angle(nChild,Miller(0,1,1,csChild)) < 5*degree
  nChild = Miller(0,1,1,csChild);
end

% Step 1
% determine child symmetry such that (011) is parallel to (XXX)
% with only one negative X -> this does not change variantId

d = angle_outer(inv(p2cV) * p2cV.SS * nChild, nParent,'noSymmetry');
d = min(d,[],2);
d = reshape(d,length(p2cV),numSym(p2cV.SS));

[~,id] = min(d,[],2);

symRot = p2cV.SS.rot;
p2cV = inv(symRot(id)) .* p2cV(:);

% determine packetId
[~,packetId] = min(reshape(angle(p2cV * nParent, nChild),[],length(nParent)),[],2);

% Step 2
% transform to packet 1

dParent = Miller({-1 0 1},{0 1 -1},{1 -1 0},csParent);
rot2p1 = orientation.map(nParent(1),nParent, ...
  dParent(1),Miller({-1 0 1},{1 0 -1},{0 -1 1},{-1 1 0},csParent));

p2cp1 = p2cV .* rot2p1(packetId);

% step 3
% determine lathId in packet 1

dChild = Miller({-1 -1 1},{-1 1 -1},csChild);

d = reshape(angle_outer(inv(p2cp1)*dChild,dParent,'noSymmetry'),[],length(dParent)*length(dChild));

% the lath id
[~,lathId] = min(d,[],2);

% the variant Id
vId = 6*(packetId-1) + lathId;

% new order we get from reordering the variant Id
[~,newOrder] = sort(vId);

%p2cV = p2cV(newOrder);

% TODO!
p2c.opt.variantMap = newOrder;

author: mtex-toolbox

repo: mtex

save_path: github-repos/MATLAB/mtex-toolbox-mtex


text:
function out = NL_BoxCorrDim(y,numBins,embedParams)
% NL_BoxCorrDim  Correlation dimension of a time series.
%
% References TSTOOL code, corrdim, to estimate the correlation dimension of a
% time-delay embedded time series using a box-counting approach.
%
% TSTOOL: http://www.physik3.gwdg.de/tstool/
%
%---INPUTS:
% y, column vector of time series data
% numBins, maximum number of partitions per axis
% embedParams [opt], embedding parameters as {tau,m} in 2-entry cell for a
%                   time-delay, tau, and embedding dimension, m. As inputs to BF_Embed.
%
%---OUTPUTS: Simple summaries of the outputs from corrdim.

% ------------------------------------------------------------------------------
% Copyright (C) 2020, Ben D. Fulcher <ben.d.fulcher@gmail.com>,
% <http://www.benfulcher.com>
%
% If you use this code for your research, please cite the following two papers:
%
% (1) B.D. Fulcher and N.S. Jones, "hctsa: A Computational Framework for Automated
% Time-Series Phenotyping Using Massive Feature Extraction, Cell Systems 5: 527 (2017).
% DOI: 10.1016/j.cels.2017.10.001
%
% (2) B.D. Fulcher, M.A. Little, N.S. Jones, "Highly comparative time-series
% analysis: the empirical structure of time series and their methods",
% J. Roy. Soc. Interface 10(83) 20130048 (2013).
% DOI: 10.1098/rsif.2013.0048
%
% This function 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/>.
% ------------------------------------------------------------------------------

doPlot = 0; % plot outputs to a figure

% ------------------------------------------------------------------------------
%% Check inputs, preliminaries
% ------------------------------------------------------------------------------
% (1) Maxmum number of partitions per axis, numBins
if nargin < 2 || isempty(numBins)
    numBins = 100; % default number of bins per axis is 100
end

% (2) Set embedding parameters to defaults
if nargin < 3 || isempty(embedParams)
    embedParams = {'ac','fnnmar'};
else
    if length(embedParams) ~= 2
        error('Embedding parameters should be formatted like {tau,m}')
    end
end

% ------------------------------------------------------------------------------
%% Embed the signal
% ------------------------------------------------------------------------------
% convert to embedded signal object for TSTOOL
s = BF_Embed(y,embedParams{1},embedParams{2},1);

if ~isa(s,'signal') && isnan(s); % embedding failed
    error('Time-series embedding to signal class for TSTOOL failed')
end

% ------------------------------------------------------------------------------
%% Run
% ------------------------------------------------------------------------------
rs = data(corrdim(s,numBins));

% Contains ldr as rows for embedding dimensions 1:m as columns;
if doPlot
    figure('color','w'); box('on');
    plot(rs,'k');
end

% ------------------------------------------------------------------------------
%% Output Statistics
% ------------------------------------------------------------------------------
% These statistics are just from intuition

m = size(rs,2); % number of embedding dimensions
ldr = size(rs,1); % not completely clear from TSTOOL what ldr represents (= 17)

for i = 2:m
    out.(sprintf('meand%u',i)) = mean(rs(:,i));
    out.(sprintf('mediand%u',i)) = median(rs(:,i));
    out.(sprintf('mind%u',i)) = min(rs(:,i));
end

for i = 2:ldr
    out.(sprintf('meanr%u',i)) = mean(rs(i,:));
    out.(sprintf('medianr%u',i)) = median(rs(i,:));
    out.(sprintf('minr%u',i)) = min(rs(i,:));
    out.(sprintf('meanchr%u',i)) = mean(diff(rs(i,:)));
end

out.stdmean = std(mean(rs));
out.stdmedian = std(median(rs));

rsstretch = rs(:);
out.medianstretch = median(rsstretch);
out.minstretch = min(rsstretch); % same as at maximum embedding dimension, m, or usually at maximum ldr (18)
out.iqrstretch = iqr(rsstretch);

end

author: benfulcher

repo: hctsa

save_path: github-repos/MATLAB/benfulcher-hctsa


text:
function [RMAOV31] = RMAOV31(X,alpha)
% RMAOV31 Three-way Analysis of Variance With Repeated Measures on One Factor Test.
%   This is a three-factor analysis of variance design in which there are repeated measures
%   on only one of the factors. In repeated measures designs, the same participants are used
%   in all conditions. This is like an extreme matching. This allows for reduction of error
%   variance due to subject factors. Fewer participants can be used in an repeated measures
%   design. Repeated measures designs make it easier to see an effect of the independent
%   variable on the dependent variable (if there is such an effect).
%   There are two different error terms. One of the error terms involves subject-to-subject
%   variability within each group or, in the case of the present design, within each cell
%   formed by the two between-group factors. The other error term involves the variability
%   within subjects. The within-subject variability can be divided into five components,
%   which include the main effect of the RM factor and all of its interactions.
%   The SS components are divided up for this design in a way that is best illustrated in a
%   SS tree, as shown:
%
%                                                      /
%                                                     | SSA
%                                            /        |
%                                           | SSAB   <  SSB
%                                           |         |
%                                 /         |         | SSAxB
%                                | SSB-S   <           \
%                                |          |
%                                |          |
%                                |          | [SSEAB]
%                                |           \
%                                |
%                        SSTO   <
%                                |           /
%                                |          | SSC
%                                |          |
%                                |          | SSAxC
%                                |          |
%                                | SSW-S   <  SSBxC
%                                 \         |
%                                           | SSAxBxC
%                                           |
%                                           | [SSEC]
%                                            \
%
%   Syntax: function [RMAOV31] = RMAOV31(X,alpha)
%
%     Inputs:
%          X - data matrix (Size of matrix must be n-by-5;dependent variable=column 1;
%              independent variable 1=column 2;independent variable 2=column 3;
%              independent variable 3=column 4; subject=column 5).
%      alpha - significance level (default = 0.05).
%    Outputs:
%            - Complete Analysis of Variance Table.
%
%    Example: From the example of Howell (2002, p. 494-498). Involving a comparision of two approaching educational
%             programs (intervention) to reduce the risk of HIV infection among African-American adolescents. Subjects
%             were male and female adolescents, and measures were taken on four different times. This is a 2x2x4
%             repeated-measures design, with intervention and sex as between-subjects factors and time as the
%             within-subjects factor. The data (table below) are frequency of condom-protected intercourse [log(x+1)].
%             We take a significance level = 0.05.
%
%                                         I1                                                       I2
%             --------------------------------------------------------------------------------------------------------------------
%                          M                            F                           M                            F
%             --------------------------------------------------------------------------------------------------------------------
%    Subject     T1     T2     T3     T4      T1     T2     T3     T4      T1     T2     T3     T4      T1     T2     T3     T4
%    -----------------------------------------------------------------------------------------------------------------------------
%       1         7     22     13     14       0      6     22     26       0      0      0      0      15     28     26     15
%       2        25     10     17     24       0     16     12     15      69     56     14     36       0      0      0      0
%       3        50     36     49     23       0      8      0      0       5      0      0      5       6      0     23      0
%       4        16     38     34     24      15     14     22      8       4     24      0      0       0      0      0      0
%       5        33     25     24     25      27     18     24     37      35      8      0      0      25     28      0     16
%       6        10      7     23     26       0      0      0      0       7      0      9     37      36     22     14     48
%       7        13     33     27     24       4     27     21      3      51     53      8     26      19     22     29      2
%       8        22     20     21     11      26      9      9     12      25      0      0     15       0      0      5     14
%       9         4      0     12      0       0      0     14      1      59     45     11     16       0      0      0      0
%      10        17     16     20     10       0      0     12      0      40      2     33     16       0      0      0      0
%    -----------------------------------------------------------------------------------------------------------------------------
%
%     Data matrix must be:
%     X = [7 1 1 1 1;22 1 1 2 1;13 1 1 3 1;14 1 1 4 1;25 1 1 1 2;10 1 1 2 2;17 1 1 3 2;24 1 1 4 2;50 1 1 1 3;36 1 1 2 3;49 1 1 3 3;
%     23 1 1 4 3;16 1 1 1 4;38 1 1 2 4;34 1 1 3 4;24 1 1 4 4;33 1 1 1 5;25 1 1 2 5;24 1 1 3 5;25 1 1 4 5;10 1 1 1 6;7 1 1 2 6;23 1 1 3 6;
%     26 1 1 4 6;13 1 1 1 7;33 1 1 2 7;27 1 1 3 7;24 1 1 4 7;22 1 1 1 8;20 1 1 2 8;21 1 1 3 8;11 1 1 4 8;4 1 1 1 9;0 1 1 2 9;12 1 1 3 9;
%     0 1 1 4 9;17 1 1 1 10;16 1 1 2 10;20 1 1 3 10;10 1 1 4 10;0 1 2 1 11;6 1 2 2 11;22 1 2 3 11;26 1 2 4 11;0 1 2 1 12;16 1 2 2 12;
%     12 1 2 3 12;15 1 2 4 12;0 1 2 1 13;8 1 2 2 13;0 1 2 3 13;0 1 2 4 13;15 1 2 1 14;14 1 2 2 14;22 1 2 3 14;8 1 2 4 14;27 1 2 1 15;
%     18 1 2 2 15;24 1 2 3 15;37 1 2 4 15;0 1 2 1 16;0 1 2 2 16;0 1 2 3 16;0 1 2 4 16;4 1 2 1 17;27 1 2 2 17;21 1 2 3 17;3 1 2 4 17;
%     26 1 2 1 18;9 1 2 2 18;9 1 2 3 18;12 1 2 4 18;0 1 2 1 19;0 1 2 2 19;14 1 2 3 19;1 1 2 4 19;0 1 2 1 20;0 1 2 2 20;12 1 2 3 20;
%     0 1 2 4 20;0 2 1 1 21;0 2 1 2 21;0 2 1 3 21;0 2 1 4 21;69 2 1 1 22;56 2 1 2 22;14 2 1 3 22;36 2 1 4 22;5 2 1 1 23;0 2 1 2 23;
%     0 2 1 3 23;5 2 1 4 23;4 2 1 1 24;24 2 1 2 24;0 2 1 3 24;0 2 1 4 24;35 2 1 1 25;8 2 1 2 25;0 2 1 3 25;0 2 1 4 25;7 2 1 1 26;0 2 1 2 26;
%     9 2 1 3 26;37 2 1 4 26;51 2 1 1 27;53 2 1 2 27;8 2 1 3 27;26 2 1 4 27;25 2 1 1 28;0 2 1 2 28;0 2 1 3 28;15 2 1 4 28;59 2 1 1 29;
%     45 2 1 2 29;11 2 1 3 29;16 2 1 4 29;40 2 1 1 30;2 2 1 2 30;33 2 1 3 30;16 2 1 4 30;15 2 2 1 31;28 2 2 2 31;26 2 2 3 31;15 2 2 4 31;
%     0 2 2 1 32;0 2 2 2 32;0 2 2 3 32;0 2 2 4 32;6 2 2 1 33;0 2 2 2 33;23 2 2 3 33;0 2 2 4 33;0 2 2 1 34;0 2 2 2 34;0 2 2 3 34;0 2 2 4 34;
%     25 2 2 1 35;28 2 2 2 35;0 2 2 3 35;16 2 2 4 35;36 2 2 1 36;22 2 2 2 36;14 2 2 3 36;48 2 2 4 36;19 2 2 1 37;22 2 2 2 37;29 2 2 3 37;
%     2 2 2 4 37;0 2 2 1 38;0 2 2 2 38;5 2 2 3 38;14 2 2 4 38;0 2 2 1 39;0 2 2 2 39;0 2 2 3 39;0 2 2 4 39;0 2 2 1 40;0 2 2 2 40;0 2 2 3 40;
%     0 2 2 4 40];
%
%     Calling on Matlab the function:
%             RMAOV31(X)
%
%     Answer is:
%
%    The number of IV1 levels are: 2
%    The number of IV2 levels are: 2
%    The number of IV3 levels are: 4
%    The number of subjects are:   40
%
%    Three-Way Analysis of Variance With Repeated Measures on One-Factor (Within -Subjects) Table.
%    -------------------------------------------------------------------------------------------------
%    SOV                           SS          df           MS             F        P      Conclusion
%    -------------------------------------------------------------------------------------------------
%    Between-Subjects         21490.344        39
%    IV1                        107.256         1        107.256         0.215   0.6457       NS
%    IV2                       3358.056         1       3358.056         6.731   0.0136        S
%    IV1xIV2                     63.756         1         63.756         0.128   0.7228       NS
%    Error(IV1xIV2)           17961.275        36        498.924
%
%    Within-Subjects          13914.250       120
%    IV3                        274.069         3         91.356         0.896   0.4456       NS
%    IV1xIV3                   1377.819         3        459.273         4.507   0.0051        S
%    IV2xIV3                    779.919         3        259.973         2.551   0.0594       NS
%    IV1xIV2xIV3                476.419         3        158.806         1.558   0.2037       NS
%    Error(IV3)               11006.025       108        101.908
%    -------------------------------------------------------------------------------------------------
%    Total                    35404.594       159
%    -------------------------------------------------------------------------------------------------
%    With a given significance level of: 0.05
%    The results are significant (S) or not significant (NS).
%
%    Created by A. Trujillo-Ortiz, R. Hernandez-Walls and F.A. Trujillo-Perez
%               Facultad de Ciencias Marinas
%               Universidad Autonoma de Baja California
%               Apdo. Postal 453
%               Ensenada, Baja California
%               Mexico.
%               atrujo@uabc.mx
%
%    Copyright.January 7, 2006.
%
%    ---Special thanks are given to Georgina M. Blanc from the Vision Center Laboratory of the
%       Salk Institute for Biological Studies, La Jolla, CA, for encouraging us to create
%       this m-file--
%
%    To cite this file, this would be an appropriate format:
%    Trujillo-Ortiz, A., R. Hernandez-Walls and F.A. Trujillo-Perez. (2006). Three-way
%      Analysis of Variance With Repeated Measures on One Factor Test. A MATLAB file.
%      [WWW document]. URL http://www.mathworks.com/matlabcentral/fileexchange/
%      loadFile.do?objectId=9605
%
%    References:
%    Howell, D. C. (2002), Statistical Methods for Psychology. 5th ed.
%             Pacific Grove, CA:Duxbury Wadsworth Group.
%

if nargin < 2,
   alpha = 0.05; %(default)
end;

if (alpha <= 0 | alpha >= 1)
   fprintf('Warning: significance level must be between 0 and 1\n');
   return;
end;

if nargin < 1,
   error('Requires at least one input argument.');
   return;
end;

a = max(X(:,2));
b = max(X(:,3));
c = max(X(:,4));
s = max(X(:,5));

disp('   ');
fprintf('The number of IV1 levels are:%2i\n', a);
fprintf('The number of IV2 levels are:%2i\n', b);
fprintf('The number of IV3 levels are:%2i\n', c);
fprintf('The number of subjects are:   %2i\n\n', s);

CT = (sum(X(:,1)))^2/length(X(:,1));  %correction term
SSTO = sum(X(:,1).^2)-CT;  %total sum of squares
v10 = length(X(:,1))-1;  %total degrees of freedom

%procedure related to the subjects.
S = [];
indice = X(:,5);
for l = 1:s
    Xe = find(indice==l);
    eval(['S' num2str(l) '=X(Xe,1);']);
    eval(['x =((sum(S' num2str(l) ').^2)/length(S' num2str(l) '));']);
    S = [S,x];
end;

%--Procedure Related to the Between-Subjects--
%procedure related to the IV1 (independent variable 1 [between-subject]).
A = [];
indice = X(:,2);
for i = 1:a
    Xe = find(indice==i);
    eval(['A' num2str(i) '=X(Xe,1);']);
    eval(['x =((sum(A' num2str(i) ').^2)/length(A' num2str(i) '));']);
    A = [A,x];
end;
SSA = sum(A)-CT;  %sum of squares for the IV1
v1 = a-1;  %degrees of freedom for the IV1
MSA = SSA/v1;  %mean square for the IV1

%procedure related to the IV2 (independent variable 2 [between-subject]).
B = [];
indice = X(:,3);
for j = 1:b
    Xe = find(indice==j);
    eval(['B' num2str(j) '=X(Xe,1);']);
    eval(['x =((sum(B' num2str(j) ').^2)/length(B' num2str(j) '));']);
    B =[B,x];
end;
SSB = sum(B)-CT;  %sum of squares for the IV2
v2 = b-1;  %degrees of freedom for the IV2
MSB = SSB/v2;  %mean square for the IV2

%procedure related to the IV1 and IV2 (between- and between- subject).
AB = [];
for i = 1:a
    for j = 1:b
        Xe = find((X(:,2)==i) & (X(:,3)==j));
        eval(['AB' num2str(i) num2str(j) '=X(Xe,1);']);
        eval(['x =((sum(AB' num2str(i) num2str(j) ').^2)/length(AB' num2str(i) num2str(j) '));']);
        AB = [AB,x];
    end;
end;
SSAB = sum(AB)-sum(A)-sum(B)+CT;  %sum of squares of the IV1xIV2
v3 = v1*v2;  %degrees of freedom of the IV1xIV2
MSAB = SSAB/v3;  %mean square for the IV1xIV2

%procedure related to the IV1-IV2-error.
SSEAB = sum(S)-sum(AB);  %sum of squares of the IV1-IV2-error
v4 = s-(a*b);  %degrees of freedom of the IV1-IV2-error
MSEAB = SSEAB/v4;  %mean square for the IV1-IV2-error

%F-statistics calculation.
F1 = MSA/MSEAB;
F2 = MSB/MSEAB;
F3 = MSAB/MSEAB;

%Probability associated to the F-statistics.
P1 = 1 - fcdf(F1,v1,v4);
P2 = 1 - fcdf(F2,v2,v4);
P3 = 1 - fcdf(F3,v3,v4);

SSBS = SSA+SSB+SSAB+SSEAB;
vBS = v1+v2+v3+v4;

%--Procedure Related to the Within-Subjects--
%procedure related to the IV3 (independent variable 3 [within-subject]).
C = [];
indice = X(:,4);
for k = 1:c
    Xe = find(indice==k);
    eval(['C' num2str(k) '=X(Xe,1);']);
    eval(['x =((sum(C' num2str(k) ').^2)/length(C' num2str(k) '));']);
    C =[C,x];
end;
SSC = sum(C)-CT;  %sum of squares for the IV2
v5 = c-1;  %degrees of freedom for the IV2
MSC = SSC/v5;  %mean square for the IV2

%procedure related to the IV1 and IV3 (between- and within- subject).
AC = [];
for i = 1:a
    for k = 1:c
        Xe = find((X(:,2)==i) & (X(:,4)==k));
        eval(['AC' num2str(i) num2str(k) '=X(Xe,1);']);
        eval(['x =((sum(AC' num2str(i) num2str(k) ').^2)/length(AC' num2str(i) num2str(k) '));']);
        AC = [AC,x];
    end;
end;
SSAC = sum(AC)-sum(A)-sum(C)+CT;  %sum of squares of the IV1xIV3
v6 = v1*v5;  %degrees of freedom of the IV1xIV3
MSAC = SSAC/v6;  %mean square for the IV1xIV3

%procedure related to the IV2 and IV3 (between- and within- subject).
BC = [];
for j = 1:b
    for k = 1:c
        Xe = find((X(:,3)==j) & (X(:,4)==k));
        eval(['BC' num2str(j) num2str(k) '=X(Xe,1);']);
        eval(['x =((sum(BC' num2str(j) num2str(k) ').^2)/length(BC' num2str(j) num2str(k) '));']);
        BC = [BC,x];
    end;
end;
SSBC = sum(BC)-sum(B)-sum(C)+CT;  %sum of squares of the IV2xIV3
v7 = v2*v5;  %degrees of freedom of the IV2xIV3
MSBC = SSBC/v7;  %mean square for the IV2xIV3

%procedure related to the IV1, IV2 and IV3 (between, between- and within- subject).
ABC = [];
for i = 1:a
    for j = 1:b
        for k = 1:c
            Xe = find((X(:,2)==i) & (X(:,3)==j) & (X(:,4)==k));
            eval(['AB' num2str(i) num2str(j) num2str(k) '=X(Xe,1);']);
            eval(['x =((sum(AB' num2str(i) num2str(j) num2str(k) ').^2)/length(AB' num2str(i) num2str(j) num2str(k) '));']);
            ABC = [ABC,x];
        end;
    end;
end;
SSABC = sum(ABC)+sum(A)+sum(B)+sum(C)-sum(AB)-sum(AC)-sum(BC)-CT;  %sum of squares of the IV1xIV2xIV3
v8 = v1*v2*v5;  %degrees of freedom of the IV1xIV2
MSABC = SSABC/v8;  %mean square for the IV1xIV2

%procedure related to the IV3-error.
EIV3 = [];
for k = 1:c
    for l = 1:s
        Xe = find((X(:,4)==k) & (X(:,5)==l));
        eval(['IV3S' num2str(k) num2str(l) '=X(Xe,1);']);
        eval(['x =((sum(IV3S' num2str(k) num2str(l) ').^2)/length(IV3S' num2str(k) num2str(l) '));']);
        EIV3 = [EIV3,x];
    end;
end;
SSEC = sum(EIV3)-sum(S)-sum(ABC)+sum(AB);  %sum of squares of the IV3-error
v9 = v4*v5;  %degrees of freedom of the IV3-error
MSEC = SSEC/v9;  %mean square for the IV3-error

%F-statistics calculation.
F4 = MSC/MSEC;
F5 = MSAC/MSEC;
F6 = MSBC/MSEC;
F7 = MSABC/MSEC;

%Probability associated to the F-statistics.
P4 = 1 - fcdf(F4,v5,v9);
P5 = 1 - fcdf(F5,v6,v9);
P6 = 1 - fcdf(F6,v7,v9);
P7 = 1 - fcdf(F7,v8,v9);

SSWS = SSC+SSAC+SSBC+SSABC+SSEC;
vWS = v5+v6+v7+v8+v9;

if P1 >= alpha;
    ds1 ='NS';
else
    ds1 =' S';
end;
if  P2 >= alpha;
    ds2 ='NS';
else
    ds2 =' S';
end;
if  P3 >= alpha;
    ds3 ='NS';
else
    ds3 =' S';
end;
if  P4 >= alpha;
    ds4 ='NS';
else
    ds4 =' S';
end;
if P5 >= alpha;
    ds5 ='NS';
else
    ds5 =' S';
end;
if  P6 >= alpha;
    ds6 ='NS';
else
    ds6 =' S';
end;
if  P7 >= alpha;
    ds7 ='NS';
else
    ds7 =' S';
end;

disp('Three-Way Analysis of Variance With Repeated Measures on One-Factor (Within -Subjects) Table.')
fprintf('-------------------------------------------------------------------------------------------------\n');
disp('SOV                           SS          df           MS             F        P      Conclusion');
fprintf('-------------------------------------------------------------------------------------------------\n');
fprintf('Between-Subjects       %11.3f%10i\n',SSBS,vBS);
fprintf('IV1                    %11.3f%10i%15.3f%14.3f%9.4f%9s\n',SSA,v1,MSA,F1,P1,ds1);
fprintf('IV2                    %11.3f%10i%15.3f%14.3f%9.4f%9s\n',SSB,v2,MSB,F2,P2,ds2);
fprintf('IV1xIV2                %11.3f%10i%15.3f%14.3f%9.4f%9s\n',SSAB,v3,MSAB,F3,P3,ds3);
fprintf('Error(IV1xIV2)         %11.3f%10i%15.3f\n\n',SSEAB,v4,MSEAB);
fprintf('Within-Subjects        %11.3f%10i\n',SSWS,vWS);
fprintf('IV3                    %11.3f%10i%15.3f%14.3f%9.4f%9s\n',SSC,v5,MSC,F4,P4,ds4);
fprintf('IV1xIV3                %11.3f%10i%15.3f%14.3f%9.4f%9s\n',SSAC,v6,MSAC,F5,P5,ds5);
fprintf('IV2xIV3                %11.3f%10i%15.3f%14.3f%9.4f%9s\n',SSBC,v7,MSBC,F6,P6,ds6);
fprintf('IV1xIV2xIV3            %11.3f%10i%15.3f%14.3f%9.4f%9s\n',SSABC,v8,MSABC,F7,P7,ds7);
fprintf('Error(IV3)             %11.3f%10i%15.3f\n',SSEC,v9,MSEC);
fprintf('-------------------------------------------------------------------------------------------------\n');
fprintf('Total                  %11.3f%10i\n',SSTO,v10);
fprintf('-------------------------------------------------------------------------------------------------\n');
fprintf('With a given significance level of: %.2f\n', alpha);
disp('The results are significant (S) or not significant (NS).');

return;

author: Sable

repo: mcbench-benchmarks


text:
classdef ZDT4 < PROBLEM
% <multi> <real> <large/none> <expensive/none>
% Benchmark MOP proposed by Zitzler, Deb, and Thiele

%------------------------------- Reference --------------------------------
% E. Zitzler, K. Deb, and L. Thiele, Comparison of multiobjective
% evolutionary algorithms: Empirical results, Evolutionary computation,
% 2000, 8(2): 173-195.
%------------------------------- Copyright --------------------------------
% Copyright (c) 2023 BIMK Group. You are free to use the PlatEMO for
% research purposes. All publications which use this platform or any code
% in the platform should acknowledge the use of "PlatEMO" and reference "Ye
% Tian, Ran Cheng, Xingyi Zhang, and Yaochu Jin, PlatEMO: A MATLAB platform
% for evolutionary multi-objective optimization [educational forum], IEEE
% Computational Intelligence Magazine, 2017, 12(4): 73-87".
%--------------------------------------------------------------------------

    methods
        %% Default settings of the problem
        function Setting(obj)
            obj.M = 2;
            if isempty(obj.D); obj.D = 10; end
            obj.lower    = [0,zeros(1,obj.D-1)-5];
            obj.upper    = [1,zeros(1,obj.D-1)+5];
            obj.encoding = ones(1,obj.D);
        end
        %% Calculate objective values
        function PopObj = CalObj(obj,PopDec)
            PopObj(:,1) = PopDec(:,1);
            g = 1 + 10*(size(PopDec,2)-1) + sum(PopDec(:,2:end).^2-10*cos(4*pi*PopDec(:,2:end)),2);
            h = 1 - (PopObj(:,1)./g).^0.5;
            PopObj(:,2) = g.*h;
        end
        %% Generate points on the Pareto front
        function R = GetOptimum(obj,N)
            R(:,1) = linspace(0,1,N)';
            R(:,2) = 1 - R(:,1).^0.5;
        end
        %% Generate the image of Pareto front
        function R = GetPF(obj)
            R = obj.GetOptimum(100);
        end
    end
end

author: BIMK

repo: PlatEMO

save_path: github-repos/MATLAB/BIMK-PlatEMO


text:
function [res] = build_and_verify_mexPlex()
% this script will build and verify mexPlex
%
% OUTPUT:
%   returns 1 if all verification tests passed
%   returns 0 if some of the verification tests failed
%
% if ReadingPLXandDDTfilesinMatlab-mexw.zip was inzipped to
%
% C:\PlexonMatlab
%
% this script should be run when Matlab's current directory is
%
% C:\PlexonMatlab\OfflineSDK\mexPlex
%
% If res is 1, all the tests passed.
%
% If you want to build mexPlex without verification, run this in Matlab:
%
% mex -output mexPlex -outdir .. PlexMethods.cpp
%
%
% Plexon made sure that mexPlex code compiles without warnings in Matlab R2009b
% under Ubintu 10.04 using gcc 4.1
% If you have trouble compiling mexPlex in Linux, please contact Matlab technical support.

% compile mexPlex
mex -output mexPlex -outdir .. PlexMethods.cpp

% make sure that <>\OfflineSDK is in Matlab path
cd ..
if length(findstr(path,pwd)) == 0
    addpath(pwd)
end
% go to tests
cd mexPlex
cd tests
% load the data extracted with mexPlex in Windows
load('mexPlexData1.dat', '-mat');

% verify that the newly built mexPlex generates the same data
t=evalc('res = verify_mexplex(data, pwd);');

if res == 0
    disp('VERIFICATION FAILED');
    t
else
    disp('VERIFICATION TESTS PASSED');
end
cd ..

author: buzsakilab

repo: buzcode

save_path: github-repos/MATLAB/buzsakilab-buzcode


text:
function subpak_test ( )

%*****************************************************************************80
%
%% SUBPAK_TEST tests the SUBPAK library.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    03 November 2011
%
%  Author:
%
%    John Burkardt
%
  timestamp ( );
  fprintf ( 1, '\n' );
  fprintf ( 1, 'SUBPAK_TEST\n' );
  fprintf ( 1, '  MATLAB version\n' );
  fprintf ( 1, '  Test the SUBPAK library.\n' );

  subpak_test01 ( );
  subpak_test02 ( );
  subpak_test03 ( );
  subpak_test04 ( );
  subpak_test05 ( );
  subpak_test06 ( );
  subpak_test07 ( );
  subpak_test08 ( );
  subpak_test09 ( );

  subpak_test10 ( );
  subpak_test11 ( );
  subpak_test12 ( );
  subpak_test13 ( );
  subpak_test14 ( );
  subpak_test15 ( );
  subpak_test16 ( );
  subpak_test17 ( );
  subpak_test18 ( );
  subpak_test19 ( );

  subpak_test20 ( );
  subpak_test21 ( );
  subpak_test22 ( );
  subpak_test225 ( );
  subpak_test24 ( );
  subpak_test25 ( );
  subpak_test26 ( );
  subpak_test27 ( );
  subpak_test28 ( );
  subpak_test29 ( );

  subpak_test30 ( );
  subpak_test31 ( );
  subpak_test32 ( );
  subpak_test33 ( );
  subpak_test34 ( );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'SUBPAK_TEST\n' );
  fprintf ( 1, '  Normal end of execution.\n' );
  fprintf ( 1, '\n' );
  timestamp ( );

  return
end


text:
function [ y2, m2, d2, f2 ] = yjf_to_ymdf_republican ( y1, j1, f1 )

%*****************************************************************************80
%
%% YJF_TO_YMDF_REPUBLICAN: YJF to YMDF date in the Republican calendar.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    07 March 2013
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, integer Y1, J1, real F1, the YJF date.
%
%    Output, integer Y2, M2, D2, real F2,
%    the YMDF date.
%

%
%  Copy the input.
%
  y2 = y1;
  j2 = j1;
  f2 = f1;
%
%  Check the input.
%
  [ y2, j2, ierror ] = yj_check_republican ( y2, j2 );

  if ( ierror ~= 0 )
    y2 = 0;
    m2 = 0;
    d2 = 0;
    f2 = 0.0;
    return
  end
%
%  Convert the input.
%
  m2 = 1;
  d2 = j2;

  [ y2, m2, d2 ] = day_borrow_republican ( y2, m2, d2 );

  [ y2, m2, d2 ] = day_carry_republican ( y2, m2, d2 );

  return
end


text:
 clc
 clear
  run cal
 run unknown_input
load force.mat
load f_un.mat
load X.mat
load Y.mat
load u.mat
n=4

for ii=1:4;

    figure(ii)
    plot(detrend(X(ii,:)),'r')
    hold on
    plot(detrend(u(:,ii)))
end

for ii=1:4;

    figure(4+ii)
    plot(detrend(X(n+ii,:)),'r')
    hold on
    plot(detrend(Y(:,ii)))
end
 figure(9)
 plot(detrend(f_un));
 hold
 plot(detrend(force(:,2)),'r')


text:
function cdf = normcdf(x, mu, sigma)
% normal CDF
%
% file:      	normcdf.m, (c) Matthew Roughan, Tue Jul 21 2009
% directory:   /home/mroughan/src/matlab/NUMERICAL_ROUTINES/
% created: 	Tue Jul 21 2009
% author:  	Matthew Roughan
% email:   	matthew.roughan@adelaide.edu.au
%
% INPUTS:
%   x      = a vector of points at which to calculate the normal CDF
%   mu     = mean of the normal
%   sigma  = std dev. of the normal
%

cdf = 0.5 * erfc(-(x-mu)/(sigma*sqrt(2)));


text:
function floyd_test ( )

%*****************************************************************************80
%
%% FLOYD_TEST tests the FLOYD library.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    02 March 2014
%
%  Author:
%
%    John Burkardt
%
  timestamp ( );
  fprintf ( 1, '\n' );
  fprintf ( 1, 'FLOYD_TEST\n' );
  fprintf ( 1, '  MATLAB version\n' );
  fprintf ( 1, '  Test the FLOYD library.\n' );

  floyd_test01 ( );
  floyd_test02 ( );
  floyd_test03 ( );
  floyd_test04 ( );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'FLOYD_TEST\n' );
  fprintf ( 1, '  Normal end of execution.\n' );
  fprintf ( 1, '\n' );
  timestamp ( );

  return
end


text:
function eqtime = clustime(some_cat)
    % These routine calculates the time in days of the eqs. in ZG.newcat relative
    % to the year 1902
    % A.Allmann
    % used to modify / use newcat.

    %rewritten by Celso Reyes 2017

    eqtime = days(some_cat.Date - datetime(1902,01,01));
end

author: CelsoReyes


text:
function fig = straightPanel98bak()
% This is the machine-generated representation of a Handle Graphics object
% and its children.  Note that handle values may change when these objects
% are re-created. This may cause problems with any callbacks written to
% depend on the value of the handle at the time the object was saved.
%
% To reopen this object, just type the name of the M-file at the MATLAB
% prompt. The M-file and its associated MAT-file must be on your path.

load straightpanel98

h0 = figure('Color',[0.8 0.8 0.8], ...
	'Colormap',mat0, ...
	'Position',[336 165 646 559], ...
	'Tag','STRAIGHT control panel v.1');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Position',[309 226 200 292], ...
	'Style','frame', ...
	'Tag','Frame2');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.65 0.65 0.65], ...
	'Position',[313 293 193 37], ...
	'Style','frame', ...
	'Tag','Frame5');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Position',[309 32 330 189], ...
	'Style','frame', ...
	'Tag','Frame1');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.8 0.8 0.8], ...
	'FontName','Helvetica', ...
	'FontSize',18, ...
	'Position',[201 528 284 23], ...
	'String','STRAIGHT control panel', ...
	'Style','text', ...
	'Tag','StaticText1');% font size 24->18  03/Sept./1999
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Callback','clear all,close all', ...
	'Position',[311 3 329 25], ...
	'String','close', ...
	'Tag','closebutton');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Position',[516 226 123 291], ...
	'Style','frame', ...
	'Tag','Frame1');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Callback','straightCIv1 peekvars', ...
	'Position',[529 439 95 21], ...
	'String','peek variables', ...
	'Tag','peakbutton');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Callback','straightCIv1 dispnsgram', ...
	'Enable','off', ...
	'Position',[515 173 112 20], ...
	'String','adaptive spectrogram', ...
	'Tag','adaptivespecbtn');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Callback','straightCIv1 dispnwsgram', ...
	'Enable','off', ...
	'Position',[517 141 111 20], ...
	'String','a. wide spectrogram', ...
	'Tag','widespecbtn');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Callback','straightCIv1 dispn2sgrambk', ...
	'Enable','off', ...
	'Position',[320 171 159 20], ...
	'String','smthd spectrogram', ...
	'Tag','smoothedspecbtn');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Callback','straightCIv1 dispn3sgram', ...
	'Enable','off', ...
	'Position',[321 108 158 20], ...
	'String','rmvd spectrogram', ...
	'Tag','removedspecbtn');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Callback','straightCIv1 playsynth', ...
	'Enable','off', ...
	'Position',[320 45 145 20], ...
	'String','Play synthesized', ...
	'Tag','playsynthbtn');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Callback','straightCIv1 playoriginal', ...
	'Enable','off', ...
	'Position',[483 44 148 20], ...
	'String','Play original', ...
	'Tag','playorgbtn');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Callback','straightCIv1 savefile', ...
	'Enable','off', ...
	'Position',[329 236 113 22], ...
	'String','save to file', ...
	'Tag','savetobtn');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Callback','straightCIv1 synthesize', ...
	'Enable','off', ...
	'Position',[424 266 80 22], ...
	'String','synthesize', ...
	'Tag','synthesizebtn');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Callback','straightCIv1 straightcore', ...
	'Enable','off', ...
	'Position',[424 334 79 22], ...
	'String','analyze 1CHX', ...
	'Tag','analyzespcbtn');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Callback','straightCIv1 source', ...
	'Enable','off', ...
	'Position',[355 367 113 22], ...
	'String','analyze source', ...
	'Tag','analyzesrcbtn');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Callback','straightCIv1 readfile', ...
	'Position',[354 401 113 22], ...
	'String','read from file', ...
	'Tag','readfilebtn');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Callback','straightCIv1 initialize', ...
	'Position',[353 438 113 22], ...
	'String','initialize', ...
	'Tag','initializebtn');
h1 = uicontrol('Parent',h0, ...
	'Position',[5 252 297 268], ...
	'Style','frame', ...
	'Tag','Frame1');
h1 = uicontrol('Parent',h0, ...
	'Position',[160 427 125 20], ...
	'String','sampling frequency Hz', ...
	'Style','text', ...
	'Tag','StaticText2');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.85 0.85 0.85], ...
	'Callback','straightCIv1 getfsmenu', ...
	'Position',[170 411 108 20], ...
	'String',[48000;44100;32000;24000;22050;20000;16000;12500;12000;11050;10000; 8000], ...
	'Style','popupmenu', ...
	'Tag','samplingfreqmenu', ...
	'Value',5);
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Position',[353 483 111 20], ...
	'String','Procedures', ...
	'Style','text', ...
	'Tag','StaticText3');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Position',[431 194 74 20], ...
	'String','Display', ...
	'Style','text', ...
	'Tag','StaticText4');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[1 1 1], ...
	'Callback',mat2, ...
	'Position',[27 459 72 20], ...
	'String','800', ...
	'Style','edit', ...
	'Tag','f0ceiledit');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[1 1 1], ...
	'Callback','straightCIv1 editf0floor', ...
	'Position',[28 411 72 20], ...
	'String','40', ...
	'Style','edit', ...
	'Tag','f0flooredit');
h1 = uicontrol('Parent',h0, ...
	'Position',[102 407 32 20], ...
	'String','Hz', ...
	'Style','text', ...
	'Tag','StaticText5');
h1 = uicontrol('Parent',h0, ...
	'Position',[101 454 32 20], ...
	'String','Hz', ...
	'Style','text', ...
	'Tag','StaticText5');
h1 = uicontrol('Parent',h0, ...
	'Position',[20 431 94 20], ...
	'String','F0 lower bound', ...
	'Style','text', ...
	'Tag','StaticText5');
h1 = uicontrol('Parent',h0, ...
	'Position',[20 483 95 17], ...
	'String','F0 higher bound', ...
	'Style','text', ...
	'Tag','StaticText5');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Callback','straightCIv1 remove2ndstructue', ...
	'Enable','off', ...
	'Position',[425 302 77 20], ...
	'String','remove 2nd', ...
	'Tag','remove2ndbtn');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Callback','straightCIv1 bandcorrbtn', ...
	'Enable','off', ...
	'Position',[319 334 85 20], ...
	'String','analyze MBX', ...
	'Tag','bandcorrbtn');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Callback','straightCIv1 dispn2sgram', ...
	'Enable','off', ...
	'Position',[320 139 158 20], ...
	'String','enhanced spectrogram', ...
	'Tag','dispn2sgrambtn');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Callback','straightCIv1 synthesizegraded', ...
	'Enable','off', ...
	'Position',[320 266 86 21], ...
	'String','synthsize grad', ...
	'Tag','synthgradbtn');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Callback','straightCIv1 disphhbspectrograme', ...
	'Enable','off', ...
	'Position',[321 77 158 20], ...
	'String','cmpst spectrogram', ...
	'Tag','cmpstspecgrambtn');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Position',[15 293 278 99], ...
	'Style','frame', ...
	'Tag','Frame3');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Position',[6 4 297 240], ...
	'Style','frame', ...
	'Tag','Frame4');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Position',[24 366 89 15], ...
	'String','FFT lngth', ...
	'Style','text', ...
	'Tag','StaticText6');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Position',[121 362 75 20], ...
	'String','w strtch in t', ...
	'Style','text', ...
	'Tag','StaticText7');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Position',[210 362 71 20], ...
	'String','pwr cnstnt', ...
	'Style','text', ...
	'Tag','StaticText8');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Position',[36 322 72 20], ...
	'String','mag. factor', ...
	'Style','text', ...
	'Tag','StaticText9');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[1 1 1], ...
	'Callback','straightCIv1 fftledit', ...
	'Position',[41 347 56 20], ...
	'String','1024', ...
	'Style','edit', ...
	'Tag','fftledit');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[1 1 1], ...
	'Callback','straightCIv1 wndwstrtchedit', ...
	'Position',[128 347 60 20], ...
	'String','1.4', ...
	'Style','edit', ...
	'Tag','wndwstrtchedit');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[1 1 1], ...
	'Callback','straightCIv1 pwrcnstntedit', ...
	'Position',[219 346 54 20], ...
	'String','0.6', ...
	'Style','edit', ...
	'Tag','pwrcnstntedit');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[1 1 1], ...
	'Callback','straightCIv1 magfactoredit', ...
	'Position',[42 307 56 20], ...
	'String','0.2', ...
	'Style','edit', ...
	'Tag','magfactoredit');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Callback','straightCIv1 pcnvslider', ...
	'Min',-1, ...
	'Position',[45 90 186 20], ...
	'String','F0 conversion', ...
	'Style','slider', ...
	'Tag','pcnvslider');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Callback','straightCIv1 fconvslider', ...
	'Min',-1, ...
	'Position',[45 50 187 20], ...
	'Style','slider', ...
	'Tag','fconvslider');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Callback','straightCIv1 sconvslider', ...
	'Min',-1, ...
	'Position',[44 10 188 20], ...
	'Style','slider', ...
	'Tag','sconvslider');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[1 1 1], ...
	'Callback','straightCIv1 delfracedit', ...
	'Position',[153 214 60 20], ...
	'String','0.2', ...
	'Style','edit', ...
	'Tag','delfracedit');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[1 1 1], ...
	'Callback','straightCIv1 pcnvedit', ...
	'Position',[236 91 60 20], ...
	'String','1', ...
	'Style','edit', ...
	'Tag','pcnvedit');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[1 1 1], ...
	'Callback','straightCIv1 fconvedit', ...
	'Position',[237 50 60 20], ...
	'String','1', ...
	'Style','edit', ...
	'Tag','fconvedit');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[1 1 1], ...
	'Callback','straightCIv1 sconvedit', ...
	'Position',[237 11 60 20], ...
	'String','1', ...
	'Style','edit', ...
	'Tag','sconvedit');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Position',[26 215 122 20], ...
	'String','relative tg dispersion', ...
	'Style','text', ...
	'Tag','StaticText10');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Position',[27 192 121 20], ...
	'String','absolute tg dispersion', ...
	'Style','text', ...
	'Tag','StaticText11');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[1 1 1], ...
	'Callback','straightCIv1 delspedit', ...
	'Position',[154 191 60 20], ...
	'String','2', ...
	'Style','edit', ...
	'Tag','delspedit');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Position',[28 170 121 20], ...
	'String','corner frequency', ...
	'Style','text', ...
	'Tag','StaticText11');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[1 1 1], ...
	'Callback','straightCIv1 cornfedit', ...
	'Position',[154 169 60 20], ...
	'String','3000', ...
	'Style','edit', ...
	'Tag','cornfedit');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Position',[27 148 121 20], ...
	'String','tg smoothness', ...
	'Style','text', ...
	'Tag','StaticText11');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[1 1 1], ...
	'Callback','straightCIv1 gdbwedit', ...
	'Position',[154 148 60 20], ...
	'String','70', ...
	'Style','edit', ...
	'Tag','gdbwedit');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Position',[70 112 121 20], ...
	'String','F0 conversion', ...
	'Style','text', ...
	'Tag','StaticText11');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Position',[47 70 161 20], ...
	'String','frequency axis conversion', ...
	'Style','text', ...
	'Tag','StaticText11');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Position',[49 29 156 20], ...
	'String','temporal axis conversion', ...
	'Style','text', ...
	'Tag','StaticText11');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Position',[221 167 31 20], ...
	'String','Hz', ...
	'Style','text', ...
	'Tag','StaticText11');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Position',[220 190 35 20], ...
	'String','ms', ...
	'Style','text', ...
	'Tag','StaticText11');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Position',[221 147 31 20], ...
	'String','Hz', ...
	'Style','text', ...
	'Tag','gdbwtxt');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[1 1 1], ...
	'Callback','straightCIv1 tpathedit', ...
	'Position',[21 259 268 20], ...
	'String','hmac117_HD:MATLAB 5:', ...
	'Style','edit', ...
	'Tag','tpathedit');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Callback','straightCIv1 delfracradio', ...
	'Position',[251 213 40 20], ...
	'Style','radiobutton', ...
	'Tag','delfracradio');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Callback','straightCIv1 delspradio', ...
	'Position',[252 191 42 20], ...
	'Style','radiobutton', ...
	'Tag','delspradio', ...
	'Value',1);
h1 = uicontrol('Parent',h0, ...
	'Position',[145 481 147 20], ...
	'String','original sound file', ...
	'Style','text', ...
	'Tag','StaticText12');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Position',[523 487 111 20], ...
	'String','AUX', ...
	'Style','text', ...
	'Tag','StaticText3');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[1 1 1], ...
	'Position',[144 461 149 20], ...
	'String','none', ...
	'Style','edit', ...
	'Tag','soundfilename');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Callback','straightCIv1 bypassbtn', ...
	'Enable','off', ...
	'Position',[320 302 82 20], ...
	'String','bypass', ...
	'Tag','bypassbtn');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Callback','straightCIv1 upsamplebtn', ...
	'Position',[446 237 60 20], ...
	'String','up ENBL', ...
	'Style','radiobutton', ...
	'Tag','upsamplebtn');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Callback','straightCIv1 resetparamsbtn', ...
	'Position',[531 243 92 20], ...
	'String','reset parameters', ...
	'Tag','resetparamsbtn');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'ButtonDownFcn','straightCIv1 F0NLbtn', ...
	'Position',[12 91 28 20], ...
	'String','NL', ...
	'Tag','F0NLbtn');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Callback','straightCIv1 FqNLbtn', ...
	'Position',[12 50 28 20], ...
	'String','NL', ...
	'Tag','FqNLbtn');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'ButtonDownFcn','straightCIv1 txNLbtn', ...
	'Position',[11 11 28 20], ...
	'String','NL', ...
	'Tag','txNLbtn');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Position',[119 322 80 20], ...
	'String','frame rate(ms)', ...
	'Style','text', ...
	'Tag','StaticText13');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[1 1 1], ...
	'Callback','straightCIv1 editshiftm', ...
	'Position',[129 306 60 20], ...
	'Style','edit', ...
	'Tag','shiftmedit');
h1 = uicontrol('Parent',h0, ...
	'Callback','straightCIv1 bininputformat', ...
	'Position',[532 394 89 20], ...
	'String','PC/Alpha (little-endian)|Sun/Mac (big-endian)', ...
	'Style','popupmenu', ...
	'Tag','bininputformat', ...
	'Value',1);
h1 = uicontrol('Parent',h0, ...
	'Callback','straightCIv1 binoutputformat', ...
	'Position',[532 351 87 22], ...
	'String','PC/Alpha (little-endian)|Sun/Mac (big-endian)', ...
	'Style','popupmenu', ...
	'Tag','binoutputformat', ...
	'Value',1);
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Position',[522 417 108 16], ...
	'String','Bin.IN format', ...
	'Style','text', ...
	'Tag','StaticText14');
h1 = uicontrol('Parent',h0, ...
	'BackgroundColor',[0.733333 0.733333 0.733333], ...
	'Position',[522 375 108 17], ...
	'String','Bin.OUT format', ...
	'Style','text', ...
	'Tag','StaticText15');
if nargout > 0, fig = h0; end

author: HidekiKawahara


text:
% POP_STDWARN - check memory options and issue warning for studies.
%
% Usage: >> pop_stdwarn;
%
% Author: Arnaud Delorme, CERCO, 2007
%
% See also: EEG_OPTIONS

% Copyright (C) Arnaud Delorme, CERCO, 2007, arno@salk.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.

res = 0;

eeglab_options;
if ~option_storedisk
    vartext = strvcat('Your memory options currently allow to store all datasets in memory (RAM)!', ' ', ...
                   'If your study contains a large number of datasets, you should change the memory', ...
                   'settings to allow EEGLAB to only read the dataset header (cancel next action and', ...
                   'use menu item "File > Memory" - first checkbox to allow at most one dataset at a', ...
                   'time in memory). Otherwise your computer might run out of memory.', ' ', ...
                   'NOTE that this is a REQUIRED step to load the tutorial study since it does not', ...
                   'contain the EEG data.', ' ');

    res = questdlg2(vartext, 'Study warning', 'Cancel', 'Ok', 'Ok');
    if strcmpi(res, 'Cancel'),return; end
end

author: sccn

repo: eeglab

save_path: github-repos/MATLAB/sccn-eeglab


text:
function [mindupper,dlower] = dnose2ell_bounds(trx,fly1,flies)

nflies = numel(flies);
mindupper = inf(1,trx(fly1).nframes);
dlower = nan(nflies,trx(fly1).nframes);
for i2 = 1:nflies,
  fly2 = flies(i2);
  if fly1 == fly2,
    continue;
  end
  [dnose2center,off10,off11,off20,off21] = dnose2center_pair(trx,fly1,fly2);
  if off10 <= off11,
    mindupper(off10:off11) = min(mindupper(off10:off11),dnose2center(off10:off11) + 2*trx(fly2).a_mm(off20:off21));
    dlower(i2,off10:off11) = dnose2center(off10:off11) - 2*trx(fly2).a_mm(off20:off21);
  end
end

author: kristinbranson

repo: JAABA


text:
classdef FuncCallClass < handle
    properties
        name
        nameUI
        argOut
        argIn
        paramIn
        help
        encodedStr
        err
    end

    methods

        % ------------------------------------------------------------
        function obj = FuncCallClass(varargin)
            %
            % Syntax:
            %   obj = FuncCallClass()
            %   obj = FuncCallClass(fcallStrEncoded)
            %   obj = FuncCallClass(fcallStrEncoded, reg)
            %
            % Example:
            %
            %   fcall = FuncCallClass('@ hmrBandpassFilt dod (dod,t hpf %0.3f 0.01 lpf %0.2f 0.5')
            %
            %       ===> FuncCallClass with properties:
            %
            %             name: 'hmrBandpassFilt'
            %           nameUI: 'hmrBandpassFilt'
            %        argOut.str: 'dod'
            %         argIn.str: '(dod,t'
            %          paramIn: [1x2 ParamClass]
            %             help: '  Perform a bandpass filter…'
            %
            obj.name       = '';
            obj.nameUI     = '';
            obj.argOut     = ArgClass().empty;
            obj.argIn      = ArgClass().empty;
            obj.paramIn    = ParamClass().empty;
            obj.help       = '';
            obj.encodedStr = '';
            obj.err        = 0;
            if nargin==0
                return;
            end

            if ischar(varargin{1}) || iscell(varargin{1})
                obj.Decode(varargin{1});
            elseif isa(varargin{1}, 'FuncCallClass')
                obj.Copy(varargin{1});
            end

            if nargin==1
                return;
            end
            obj.AddUsageInfo(varargin{2});
        end

        % ----------------------------------------------------------------------------------
        function Copy(obj, obj2, reg)
            if isempty(obj)
                obj = FuncCallClass();
            end
            if nargin<3
                reg = RegistriesClass.empty();
            end
            obj.name = obj2.name;
            obj.nameUI = obj2.nameUI;
            obj.argOut = obj2.argOut.copy();     % shallow copy ok because ArgClass has no handle properties
            obj.argIn = obj2.argIn.copy();       % shallow copy ok because ArgClass has no handle properties
            for ii=1:length(obj2.paramIn)
                obj.paramIn(ii) = obj2.paramIn(ii).copy();   % shallow copy ok because ParamClass has no handle properties
            end
            obj.help = obj2.help;
            obj.encodedStr = obj2.encodedStr;
            obj.AddUsageInfo(reg);
        end

        % ------------------------------------------------------------
        function helpstr = GetHelp(obj)
            if isempty(obj.help)
                fhelp = FuncHelpClass(obj.name);
                obj.help = fhelp.GetDescr();
            end
            helpstr = obj.help;
        end

        % ------------------------------------------------------------
        function name = GetName(obj)
            name = obj.name;
        end

        % ------------------------------------------------------------
        function name = GetUsageName(obj)
            name = obj.nameUI;
        end

        % ------------------------------------------------------------
        function idx = GetParamIdx(obj, key)
            idx = [];
            if ~exist('key','var') || isempty(key)
                key=1;
            end
            if ischar(key)
                for ii=1:length(obj.paramIn)
                    if strcmp(key, obj.paramIn(ii).name)
                        idx=ii;
                        break;
                    end
                end
            elseif iswholenum(key) && (key <= length(obj.paramIn))
                idx = key;
            end
        end

        % ------------------------------------------------------------
        function phelp = GetParamHelp(obj, key)
            phelp = '';
            if isempty(obj.paramIn)
                return
            end
            idx = obj.GetParamIdx(key);
            if isempty(idx)
                return;
            end
            if isempty(obj.paramIn(idx).help)
                fhelp = FuncHelpClass(obj.name);
                obj.paramIn(idx).help = fhelp.GetParamDescr(obj.paramIn(idx).name);
            end
            phelp = obj.paramIn(idx).help;
        end

        % ------------------------------------------------------------
        function fmt = GetParamFormat(obj, key)
            fmt = '';
            if isempty(obj.paramIn)
                return
            end
            idx = obj.GetParamIdx(key);
            if isempty(idx)
                return;
            end
            fmt = obj.paramIn(idx).format;
        end

        % ------------------------------------------------------------
        function val = GetParamVal(obj, key)
            val = '';
            if isempty(obj.paramIn)
                return
            end
            idx = obj.GetParamIdx(key);
            if isempty(idx)
                return;
            end
            val = obj.paramIn(idx).value;
        end

        % ------------------------------------------------------------
        function valstr = GetParamValStr(obj, key)
            valstr = '';
            if isempty(obj.paramIn)
                return
            end
            idx = obj.GetParamIdx(key);
            if isempty(idx)
                return;
            end
            valstr = sprintf(obj.paramIn(idx).format, obj.paramIn(idx).value);
        end

        % ------------------------------------------------------------
        function inputs = GetInputs(obj)
           inputs = obj.argIn.Extract();
        end

        % ------------------------------------------------------------
        function outputs = GetOutputs(obj)
           outputs = obj.argOut.Extract();
        end

        % ----------------------------------------------------------------------------------
        function SetUsageName(obj, usagename)
            if nargin<2
                usagename='';
            end

            % If usage name is already set, then we're done
            k = find((obj.nameUI==':')==1);
            if ~isempty(k)
                if (k(1) > 1) && (k(1) < length(obj.nameUI))  && isempty(usagename)
                	return;
            	end
            end
            if isempty(usagename)
                obj.nameUI = obj.name;
            else
                obj.nameUI = [obj.name, ':  ', usagename];
            end
        end

        % ----------------------------------------------------------------------------------
        function DecodeArgIn(obj)
            if isempty(obj.argIn.str)
                return
            end
            s = strtrim(obj.argIn.str);
            if s(1)~='('
                return;
            end
            args = str2cell_fast(s(2:end),',');
            fhelp = FuncHelpClass(obj.name);
            for ii=1:length(args)
                obj.argIn.vars(ii).name = args{ii};
                obj.argIn.vars(ii).help = fhelp.GetParamDescr(ii);
            end
        end

        % ----------------------------------------------------------------------------------
        function Decode(obj, fcallStrEncoded)
            %
            % Syntax:
            %   obj = Decode(fcallStrEncoded)
            %
            % Example:
            %
            %   fcall = FuncCallClass()
            %   fcall.Decode('@ hmrBandpassFilt dod (dod,t hpf %0.3f 0.01 lpf %0.2f 0.5')
            %
            %       ===> FuncCallClass with properties:
            %
            %          name: 'hmrBandpassFilt'
            %        nameUI: 'hmrBandpassFilt'
            %        argOut: 'dod'
            %         argIn.str: '(dod,t'
            %       paramIn: [1x2 ParamClass]
            %          help: '  Perform a bandpass filter…'
            %
            obj.err = 0;
            if nargin<2
                obj.err=-1;
                return;
            end
            if isempty(fcallStrEncoded)
                obj.err=-1;
                return;
            end
            if ~ischar(fcallStrEncoded)
                obj.err=-1;
                return;
            end
            obj.encodedStr = fcallStrEncoded;

            C = textscan(fcallStrEncoded, '%s');
            if C{1}{1}(1)~='@'
                textstr = [{'@'}; C{1}];
            else
                textstr = C{1};
            end
            nstr = length(textstr);
            flag = 0;
            for ii=1:nstr
                if flag==0 || textstr{ii}(1)=='@'
                    if textstr{ii}=='%'
                        flag = 999;
                    elseif textstr{ii}=='@'
                        k = strfind(textstr{ii+1},',');
                        if ~isempty(k)
                            obj.name   = textstr{ii+1}(1:k-1);
                            obj.nameUI = textstr{ii+1}(k+1:end);
                            k = strfind(obj.nameUI,'_');
                            obj.nameUI(k)=' ';
                        else
                            obj.name = textstr{ii+1};
                            obj.nameUI = obj.name;
                        end
                        obj.GetHelp();
                        if isempty(obj.argOut)
                            obj.argOut = ArgClass();
                        end
                        if isempty(obj.argIn)
                            obj.argIn = ArgClass();
                        end
                        if length(textstr)<(ii+2)
                            continue
                        end
                        obj.argOut.str = textstr{ii+2};
                        if length(textstr)<(ii+3)
                            continue
                        end
                        obj.argIn.str = textstr{ii+3};
                        obj.DecodeArgIn();
                        flag = 3;
                    else
                        % If function call string continues, means we have
                        % user-settable params, since params follow input
                        % arguments
                        pname = textstr{ii};
                        if ~isalnum(pname(1))
                            obj.err=-1;
                            return;
                        end
                        if ii+1>length(textstr)
                            obj.err=-1;
                            return;
                        end
                        for jj = 1:length(textstr{ii+1})
                            if textstr{ii+1}(jj)=='_'
                                textstr{ii+1}(jj) = ' ';
                            end
                        end
                        if length(textstr)<(ii+2)
                            continue
                        end
                        pformat = textstr{ii+1};
                        for jj = 1:length(textstr{ii+2})
                            if textstr{ii+2}(jj)=='_'
                                textstr{ii+2}(jj) = ' ';
                            end
                        end
                        pvalue = str2num(textstr{ii+2});
                        % Save default values in ParamClass
                        obj.paramIn(end+1) = ParamClass(pname, pformat, pvalue, pvalue);
                        obj.GetParamHelp(length(obj.paramIn));
                        flag = 2;
                    end
                else
                    flag = flag-1;
                end
            end
        end

        % ----------------------------------------------------------------------------------
        function fcallStrEncoded = Encode(obj)
            %
            % Syntax:
            %   fcallStrEncoded = obj.Encode()
            %
            % Example:
            %
            %   fcall = FuncCallClass()
            %   fcall.Decode('@ hmrBandpassFilt dod (dod,t hpf %0.3f 0.01 lpf %0.2f 0.5')
            %   s = fcall.Encode()
            %
            %         '@ hmrBandpassFilt dod (dod,t hpf %0.3f 0.01 lpf %0.2f 0.5'
            %

            % Encode params str
            paramInStr = '';
            for ii=1:length(obj.paramIn)
                if ii<length(obj.paramIn)
                    space = ' ';
                else
                    space = '';
                end
                if isempty(paramInStr)
                    paramInStr = sprintf('%s%s', obj.paramIn(ii).Encode(), space);
                else
                    paramInStr = sprintf('%s%s%s', paramInStr, obj.paramIn(ii).Encode(), space);
                end
            end

            obj.encodedStr = sprintf('@ %s %s %s %s', obj.name, obj.argOut.Encode(), obj.argIn.Encode(), paramInStr);

            fcallStrEncoded = obj.encodedStr;
        end

    end

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % Comparison methods and overriden operators
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    methods

        % ----------------------------------------------------------------------------------
        % Override == operator:
        % ----------------------------------------------------------------------------------
        function B = eq(obj, obj2)
            B = 0;
            if isa(obj2, 'FuncCallClass')
                if ~strcmp(obj.name, obj2.name)
                    return;
                end
                if ~strcmp(obj.argOut.str, obj2.argOut.str)
                    return;
                end
                if ~strcmp(obj.argIn.str, obj2.argIn.str)
                    return;
                end
                if length(obj.paramIn) ~= length(obj2.paramIn)
                    return;
                end
%               Must have the same number of params, but their individual
%               lengths can differ

            elseif isstruct(obj2)
                % Name
                k = find(obj.name=='_');
                s1 = obj.name;
                s2 = obj2.funcName;
                if length(k)==1
                    s1 = obj.name(k(1)+1:end);
                elseif length(k)>1
                    s1 = obj.name(k(1)+1:k(end)-1);
                end
                if ~includes(s2,s1)
                    % if func names differ check if the user friendly names
                    % are similar...
                    if ~includes(obj2.funcNameUI, obj.nameUI)
                        if ~includes(obj.nameUI, obj2.funcNameUI)
                            return;
                        end
                    end
                end

                % We don't necessarily have to have the same number of
                % params to be equal as long as all the params in obj
                % exist in obj2 in the same order.
                eq = 0;
                for ii=1:length(obj.paramIn)
                    for jj=1:length(obj2.funcParam)
                        paramIn2.name = obj2.funcParam{jj};
                        paramIn2.format = obj2.funcParamFormat{jj};
                        paramIn2.value = obj2.funcParamVal{jj};
                        eq = obj.paramIn(ii) == paramIn2;
                        if eq==1
                            break;
                        end
                        continue;
                    end
                    if eq~=1
                        B = eq;
                        return;
                    end
                end
            end
            B = 1;
        end

        % ----------------------------------------------------------------------------------
        % Override ~= operator:
        % ----------------------------------------------------------------------------------
        function B = ne(obj, obj2)
            r = obj == obj2;
            if r ~= 1
                B = 1;
            else
                B = 0;
            end
        end

        % ----------------------------------------------------------------------------------
        function scorefinal = Compare(obj, obj2)
            score = [];
            if strcmp(obj.name, obj2.name)
                score(end+1) = 0.50;
            elseif ~isempty(findstr(obj.name, obj2.name))
                score(end+1) = 0.30;
            else
                score(end+1) = 0;
            end
            score(end+1) = 0.16 * obj.argOut.Compare(obj2.argOut);
            score(end+1) = 0.16 * obj.argIn.Compare(obj2.argIn);

            % For parameters first get separate score then add to total
            scoreParams = zeros(1,max([length(obj.paramIn), length(obj2.paramIn)]));

            for ii = 1:length(obj.paramIn)
                for jj = 1:length(obj2.paramIn)
                    if strcmp(obj.paramIn(ii).GetName(), obj2.paramIn(jj).GetName())
                        scoreParams(ii) = obj.paramIn(ii).Compare(obj2.paramIn(jj));
                        if ii ~= jj
                            scoreParams(ii) = .75 * scoreParams(ii);
                        end
                    end
                end
            end

            % Tally up final results
            score = [score(:)', 0.18 * mean(scoreParams(:))'];
            scorefinal = 100*sum(score);
        end

    end

    methods

        % ----------------------------------------------------------------------------------
        function val = GetErr(obj)
            val = obj.err;
        end

        % -----------------------------------------------------------------
        function maxnamelen = GetMaxParamNameLength(obj)
            maxnamelen = 0;
            for iParam = 1:length(obj.paramIn)
                if length(obj.paramIn(iParam).name) > maxnamelen
                    maxnamelen = length(obj.paramIn(iParam).name)+1;
                end
            end
        end

        % -----------------------------------------------------------------
        function AddHelpUsageStr(obj, fcallstr)
            if isempty(obj)
                return;
            end
            if nargin<2
                return;
            end
            if isempty(fcallstr)
                return;
            end
            n = length(fcallstr);

            % Check to make sure we haven't already added the usage function call as may
            % happend when selecting wrong config file
            if strncmp(fcallstr, obj.help, n)
                return;
            end
            sep = repmat('-', 1,n);
            obj.help = sprintf('%s\n%s\n%s', fcallstr, sep, obj.help);
        end

        % -----------------------------------------------------------------
        function n = GetParamNum(obj)
            n = length(obj.paramIn);
        end

        % -----------------------------------------------------------------
        function name = GetParamName(obj, idx)
            name = '';
            if nargin<2
                return;
            end
            if ~iswholenum(idx)
                return;
            end
            if ~isscalar(idx)
                return;
            end
            if idx<1 || idx>length(obj.paramIn)
                return;
            end
            name = obj.paramIn(idx).GetName();
        end

        % -----------------------------------------------------------------
        function AddUsageInfo(obj, arg)
            if nargin<2
                return;
            end
            if isa(arg, 'RegistriesClass')
                reg = arg;
                usagename = reg.GetUsageName(obj);
                fcallstr = reg.GetFuncCallStrDecoded(obj.name, usagename);
                obj.AddHelpUsageStr(fcallstr);
            elseif ischar(arg)
                usagename = arg;
            end
            obj.SetUsageName(usagename);
        end

        % ----------------------------------------------------------------------------------
        function nbytes = MemoryRequired(obj)
            fields = properties(obj);
            nbytes = zeros(length(fields),1);
            if isempty(obj)
                nbytes = 0;
                return
            end
            for ii = 1:length(fields)
                fieldstr = sprintf('obj.%s', fields{ii});
                if ~eval('isempty(fieldstr)')
                    nbytes(ii) =  eval(sprintf('sizeof(%s);', fieldstr));
                end
            end
            nbytes = sum(nbytes);
        end

        % ----------------------------------------------------------------------------------
        function errmsg = CheckParams(obj)
            errmsg = '';
            paramValStr = '';
            if exist([obj.name, '_errchk'], 'file')  % If errchk fn is on path
                for i = 1:length(obj.paramIn)  % Assemble list of args
                   paramValStr = [paramValStr, obj.paramIn(i).GetFormattedValue()]; %#ok<AGROW>
                   if i < length(obj.paramIn)
                       paramValStr = [paramValStr, ',']; %#ok<AGROW>
                   end
                end
                % Call the errchk function which returns a non-empty string
                % if there is an error
                eval(['errmsg = ', obj.name, '_errchk(', paramValStr, ')']);
                if ~isempty(errmsg)
                   errmsg = [obj.name, ': ', errmsg];
                end
            else
               return;
            end
        end

        % ----------------------------------------------------------------------------------
        function val = GetVar(obj, name)
            val = [];
            if isempty(obj)
                return;
            end
            for ii = 1:length(obj.paramIn)
                if strcmp(name, obj.paramIn(ii).GetName())
                    val = obj.paramIn(ii).GetValue();
                    break;
                end
            end
        end

    end

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % Private methods
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    methods (Access = 'private')

    end
end

author: BUNPC


text:
classdef MeshPlotter_1D < MeshPlotter & PatchedMeshPlotter_Abstract
    methods (Access = protected, Static)
        function plotSurface(ax,coord,connec)
            hold on
            ncells = size(connec,1);
            for icell = 1:ncells
                plot(ax,coord(connec(icell,:),1),coord(connec(icell,:),2),'r.-','MarkerEdgeColor',[0.5 0 0],'MarkerSize',3);
            end
        end
    end
end

author: SwanLab

repo: Swan

save_path: github-repos/MATLAB/SwanLab-Swan


text:
function DCV=plsldardcv(X,y,A,K,method,Nmcs,OPT,order)
%+++ Repeaded double cross validation Cross-validation for PLS-LDA
%+++ Input:  X: m x n  (Sample matrix)
%            y: m x 1  (measured property)
%            A: The max PC for cross-validation
%            K: fold. when K = m, it is leave-one-out CV
%       method: pretreatment method. Contains: autoscaling, center etc.
%          OPT: =1 Print process.
%               =0 No print.
%               pareto,minmax,center or none.
%+++ Order: =1  sorted. For CV partition.
%           =0  random, default.
%+++ Output: Structural data: CV
%+++ Hongdong Li, Oct. 16, 2008.
%+++ Revised in Jan.12, 2009.

if nargin<8;order=0;end;
if nargin<7;OPT=1;end;
if nargin<6;Nmcs=100;end;
if nargin<5;method='autoscaling';end;
if nargin<4;K=10;end;
if nargin<3;A=2;end;

check=0; %+++ status variable:  1: Inf
[y,indexyy]=sort(y);
X=X(indexyy,:);
[Mx,Nx]=size(X);
Qs=floor(Mx*(1-1/K));

yytest=[];yp=[];
nLV=zeros(Nmcs,1);
predError=zeros(Nmcs,1);

for group=1:Nmcs
    perm=randperm(Mx);
    calk=perm(1:Qs);testk=perm(Qs+1:end);

    Xcal=X(calk,:);ycal=y(calk);
    Xtest=X(testk,:);ytest=y(testk);

    CV=plsldacv(Xcal,ycal,A,K,method,0,order);
    optPC=CV.optPC;
    if CV.check==1;check==1;break;end;
    LDA=plslda(Xcal,ycal,optPC,method);
    ypred=plsldaval(LDA,Xtest,ytest);
    yytest=[yytest;ytest];
    predError(group)=sum(sign(ypred)~=ytest)/length(ytest);
    yp=[yp;ypred;];
    nLV(group)=optPC;
    if OPT==1;fprintf('The %d/%dth outer loop finished.\n',group,Nmcs);end;
end

%+++ Find the most frequently chosen nLV.
uniLV=unique(nLV);
for j=1:length(uniLV); freq(j)=length(find(nLV==uniLV(j)));end
[maxf,maxindex]=max(freq);
optPC=uniLV(maxindex(1));

%+++ output
if check==0
  F=roccurve(yytest,yp,0);
  error_rate=sum(sign(yp)~=yytest)/length(yp);
  DCV.method=method;
  DCV.check=check;
  DCV.minCV=error_rate;
  DCV.sensitivity=F.sensitivity;
  DCV.specificity=F.specificity;
  DCV.predError=predError;
  DCV.nLV=nLV;
  DCV.optPC=optPC;
elseif check==1
  DCV.method=method;
  DCV.check=check;
end

author: viggin

repo: domain-adaptation-toolbox


text:
function trans = fitAffineTransform3d(ref, src)
%FITAFFINETRANSFORM3D Compute the affine transform that best register two 3D point sets.
%
%   TRANS = fitAffineTransform3d(REF, SRC)
%   Returns the affine transform matrix that minimizes the distance between
%   the reference point set REF and the point set SRC after transformation.
%   Both REF and SRC must by N-by-3 arrays with the same number of rows,
%   and the points must be in correspondence.
%   The function minimizes the sum of the squared distances:
%   CRIT = sum(distancePoints3d(REF, transformPoint3d(PTS, TRANSFO)).^2);
%
%   Example
%     N = 50;
%     pts = rand(N, 3)*10;
%     trans = createRotationOx([5 4 3], pi/4);
%     pts2 = transformPoint3d(pts, trans);
%     pts3 = pts2 + randn(N, 3)*2;
%     fitted = fitAffineTransform3d(pts, pts2);
%
%
%   See also
%     transforms3d, transformPoint3d, transformVector3d,
%     fitAffineTransform2d, registerPoints3dAffine
%

% ------
% Author: David Legland
% E-mail: david.legland@inrae.fr
% Created: 2009-07-31, using Matlab 7.7.0.471 (R2008b)
% Copyright 2009-2022 INRAE - Cepia Software Platform

% number of points
N = size(src, 1);
if size(ref, 1) ~= N
    error('Requires the same number of points for both arrays');
end

% main matrix of the problem
tmp = [src(:,1) src(:,2) src(:,3) ones(N,1)];
A = [...
    tmp zeros(N, 8) ; ...
    zeros(N, 4) tmp zeros(N, 4) ; ...
    zeros(N, 8) tmp ];

% conditions initialisations
B = [ref(:,1) ; ref(:,2) ; ref(:,3)];

% compute coefficients using least square
coefs = A\B;

% format to a matrix
trans = [coefs(1:4)' ; coefs(5:8)'; coefs(9:12)'; 0 0 0 1];

author: mattools

repo: matGeom

save_path: github-repos/MATLAB/mattools-matGeom


text:
%SHOW Display axes of affine mappings as images, if available
%
%    SHOW(W,N,BACKGROUND)
%
% If W is a affine mapping operating in a space defined by images
% (i.e. each object in the space is an image) and the image size is
% properly stored in W (SIZE_IN), then the images corresponding to the axes
% of the affine mapping are displayed.
%
% The number of horizontal images is determined by N. If N is not given an
% approximately square window is generated.
%
% Borders between images and empty images are given the value
% BACKGROUND (default: gray (0.5));

author: marianux

repo: ecg-kit

save_path: github-repos/MATLAB/marianux-ecg-kit


text:
function   noise_psd_init =init_noise_tracker_ideal_vad(noisy,fr_size,fft_size,hop,sq_hann_window)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%This m-file computes an initial noise PSD estimate by means of a
%%%%Bartlett estimate.
%%%%Input parameters:   noisy:          noisy signal
%%%%                    fr_size:        frame size
%%%%                    fft_size:       fft size
%%%%                    hop:            hop size of frame
%%%%                    sq_hann_window: analysis window
%%%%Output parameters:  noise_psd_init: initial noise PSD estimate
%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%Author: Richard C. Hendriks, 15/4/2010
%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%

for I=1:5
    noisy_frame=sq_hann_window.*noisy((I-1)*hop+1:(I-1)*hop+fr_size);
    noisy_dft_frame_matrix(:,I)=fft(noisy_frame,fft_size);
end
    noise_psd_init=mean(abs(noisy_dft_frame_matrix(1:fr_size/2+1,1:end)).^2,2);%%%compute the initialisation of the noise tracking algorithms.


text:
%===========================================================================
% Triangle Wave Fourier Series Demo  (triangle_wave_fourier_series_demo.m)
%==========================================================================
% The user can design various sawtooth wave by determining its period,
% time shift, dc value, etc. Then the program can automatically compute its
% Fourier series representation, and plot its amplitude spectrum and phase
% spectrum.
%
%
%
% By Jing Tian Email: scuteejtian@hotmail.com
%
%

function triangle_wave_fourier_series_demo

clc; close all; clear all;

%parameter of input triangle wave
T0 = 10;    % period
A = 1;
dc = 1;     % dc level
ts = 0;     % time shift, positive: move right. negative: move left
M = 4;      % How many period are shown

Nf = M*T0;       %number of FS components, i.e., C(-Nf),...,C(-1),C(0),C(1),...C(Nf).
w0 = 2*pi/T0;   % frequency

%Figure 1, plot triangle wave
x = -M/2*T0:0.01:M/2*T0;

syms t n y a1 a2 a3 a4 y1 y2
y = (sym('Heaviside(t+a1)')-sym('Heaviside(t-a2)')) * (-A/T0*2*t+A)...
    + (sym('Heaviside(t+a3)')-sym('Heaviside(t-a4)')) * (A/T0*2*t+A);
y = subs(y,a1,0);
y = subs(y,a2,T0/2);
y = subs(y,a3,T0/2);
y = subs(y,a4,0);
y=simple(y);
f = subs(y,t,x);

%plot triangle wave
figure1 = figure(1);
axes1 = axes('FontSize',14,'Parent',figure1);
box(axes1,'on');
hold(axes1,'all');
ylim(axes1,[dc-2*A dc+2*A]);
grid;
title(['Triangle wave']);
xlabel('t (seconds)'); ylabel('Amplitude');

xx = (x>=0).*(x-ts-fix((x-ts+T0/2)/T0).*T0) + (x<0).*(x-ts-fix((x-ts-T0/2)/T0).*T0);
yy = double(subs(y,t,xx))+dc;
plot(x,yy,'LineWidth',2,'color','b');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% closed-form of Cn (KEY EQUATION) %%%%%%%%%%
%Compute the closed-form of Cn; i.e.,
%C0 = 1/T0 * integral(f(t)) over [-T0/2, T0/2]
%Cn = 1/T0 * integral(f(t)*exp(-j*n*w0*t)) over [-T0/2, T0/2]

C0=int(y,t,-T0/2,T0/2)/T0;
Cs=int(y*exp(-j*w0*n*t)/T0,t,-T0/2,T0/2);
C0=simple(C0);
Cs=simple(Cs);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% closed-form of Cn (KEY EQUATION) %%%%%%%%%%

%Figure 2, plot amplitude spectrum
figure2 = figure(2);
axes2 = axes('FontSize',14,'Parent',figure2);
box(axes2,'on');
hold(axes2,'all');
title(['Amplitude Spectrum']);
xlabel('n'); ylabel('Amplitude');

%Compute Cn and plot its amplitude
for k=-Nf:1:Nf
    if k==0
        c = abs(double(C0));        %C0
    else
        c = double(subs(Cs,n,k));   %Cn, substitue n=k into the above closed-form of Cn
    end

    stem(k, abs(c),'color','b','MarkerSize',5);                  %plot

end

%Figure 3, plot phase
figure3 = figure(3);
axes3 = axes('FontSize',14,'Parent',figure3);
box(axes3,'on');
hold(axes3,'all');
title(['Phase Spectrum']);
xlabel('n'); ylabel('Phase (degrees)');

%Compute Cn and plot its angle
for k=-Nf:1:Nf
    if k==0
        c = abs(double(C0));        %C0
    else
        c = double(subs(Cs,n,k));   %Cn, substitue n=k into the above closed-form of Cn
    end

    stem(k, sign(k)*angle(c)*180/pi,'color','b','MarkerSize',5);    %plot

end