text:
function [ a, seed ] = r8ci_random ( n, seed )

%*****************************************************************************80
%
%% R8CI_RANDOM randomizes a R8CI matrix.
%
%  Discussion:
%
%    The R8CI storage format is used for an N by N circulant matrix.
%    An N by N circulant matrix A has the property that the entries on
%    row I appear again on row I+1, shifted one position to the right,
%    with the final entry of row I appearing as the first of row I+1.
%    The R8CI format simply records the first row of the matrix.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    04 February 2004
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, integer N, the order of the matrix.
%    N must be positive.
%
%    Input, integer SEED, a seed for the random number generator.
%
%    Output, real A(N), the R8CI matrix.
%
%    Output, integer SEED, an updated seed for the random number generator.
%
  for i = 1 : n
    [ a(i), seed ] = r8_uniform_01 ( seed );
  end

  return
end


text:
%
% Polynomial power  h = f^k
%
% Syntax:  >> h = PolynomialPower(f,k)
%     or   >> h = ppower(f,k)
%
% Input:     f --- (string)  polynomial
%            k --- (integer) exponent
%
% Output:    h --- (string) polynomial f^k if k is nonnegative
%
% Example:   >> PolynomialPower('x*y+1',3)
%
%            ans =
%
%            1 + 3*x*y + 3*x^2*y^2 + x^3*y^3

author: zarathustr

repo: LibQPEP

save_path: github-repos/MATLAB/zarathustr-LibQPEP


text:
%% MTEX check calcEBSD and calcODF
% check for the dependency between the number of sample
% orientations and the error between the estimated and the
% true ODF

for i = 1:5

  ebsd = discreteSample(SantaFe,10^i);

  odf = calcODF(ebsd);

  e(i) = calcError(odf,SantaFe,'resolution',2.5*degree);

end

plot(e)

author: mtex-toolbox

repo: mtex

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


text:
function [ v, more ] = tetrahedron_lattice_layer_point_next ( c, v, more )

%*****************************************************************************80
%
%% TETRAHEDRON_LATTICE_LAYER_POINT_NEXT: next tetrahedron lattice layer point.
%
%  Discussion:
%
%    The tetrahedron lattice layer L is bounded by the lines
%
%      0 <= X,
%      0 <= Y,
%      0 <= Z,
%      L - 1 < X / C(1) + Y / C(2) + Z/C(3) <= L.
%
%    In particular, layer L = 0 always contains the single point (0,0).
%
%    This function returns, one at a time, the points that lie within
%    a given tetrahedron lattice layer.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    08 July 2009
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, integer C(4), coefficients defining the
%    lattice layer in entries 1 to 3, and the laver index in C(4).
%    The coefficients should be positive, and C(4) must be nonnegative.
%
%    Input/output, integer V(3).  On first call for a given layer,
%    the input value of V is not important.  On a repeated call for the same
%    layer, the input value of V should be the output value from the previous
%    call.  On output, V contains the next lattice layer point.
%
%    Input/output, logical MORE.  On input, set MORE to FALSE to indicate
%    that this is the first call for a given layer.  Thereafter, the input
%    value should be the output value from the previous call.  On output,
%    MORE is TRUE if the returned value V is a new point.
%    If the output value is FALSE, then no more points were found,
%    and V was reset to 0, and the lattice layer has been exhausted.
%
  n = 3;
%
%  Treat layer C(N+1) = 0 specially.
%
  if ( c(n+1) == 0 )
    if ( ~more )
      v(1:n) = 0;
      more = 1;
    else
      more = 0;
    end
    return
  end
%
%  Compute the first point.
%
  if ( ~more )

    v(1) = ( c(n+1) - 1 ) * c(1) + 1;
    v(2:3) = 0;
    more = 1;

  else

    c1n = i4vec_lcm ( n, c );

    rhs1 = c1n * ( c(n+1) - 1 );
    rhs2 = c1n *   c(n+1);
%
%  Can we simply increase X?
%
    v(1) = v(1) + 1;

    lhs = ( c1n / c(1) ) * v(1) ...
        + ( c1n / c(2) ) * v(2) ...
        + ( c1n / c(3) ) * v(3);

    if ( lhs <= rhs2 )
%
%  No.  Increase Y, and set X so we just exceed RHS1...if possible.
%
    else

      v(2) = v(2) + 1;

      v(1) = floor ( ( c(1) * ( rhs1 - ( c1n / c(2) ) * v(2) ...
                                     - ( c1n / c(3) ) * v(3) ) ) / c1n );
      v(1) = max ( v(1), 0 );

      lhs = ( c1n / c(1) ) * v(1) ...
          + ( c1n / c(2) ) * v(2) ...
          + ( c1n / c(3) ) * v(3);

      if ( lhs <= rhs1 )
        v(1) = v(1) + 1;
        lhs = lhs + c1n / c(1);
      end
%
%  We have increased Y by 1.  Have we stayed below the upper bound?
%
      if ( lhs <= rhs2 )

      else
%
%  No.  Increase Z, and set X so we just exceed RHS1...if possible.
%
        v(3) = v(3) + 1;
        v(2) = 0;
        v(1) = floor ( ( c(1) * ( rhs1 - ( c1n / c(2) ) * v(2) ...
                                       - ( c1n / c(3) ) * v(3) ) ) / c1n );
        v(1) = max ( v(1), 0 );

        lhs = ( c1n / c(1) ) * v(1) ...
            + ( c1n / c(2) ) * v(2) ...
            + ( c1n / c(3) ) * v(3);

        if ( lhs <= rhs1 )
          v(1) = v(1) + 1;
          lhs = lhs + c1n / c(1);
        end

        if ( lhs <= rhs2 )

        else
          more = 0;
          v(1:n) = 0;
        end

      end
    end
  end

  return
end

author: johannesgerer

repo: jburkardt-m


text:
%% rand_angle
% Below is a demonstration of the features of the |rand_angle| function

%%
clear; close all; clc;

%% Syntax
% |a=rand_angle(siz);|

%% Description
% This function generates a matrix or array of uniformly distributed random
% angles (of the size siz) in the range [0 2*pi]. The function operates by
% first creating angles in the range 0-pi/2. The angles are next converted
% to unit vectors in the unit circle. The X and Y components of these
% vectors are next independantly and randomly negated. This negating or
% flipping operation causes the vectors to uniformly but randomly span the
% entire cirle. Nexts the vectors are converted to an angle in the range [0
% 2*pi].

%%
% Plot settings for examples
markerSize=25;
lineWidth=3;
fontSize=35;

%% Examples
%

siz=[500,1]; %Size of desired output
a=rand_angle(siz); % The random angles

%%

cFigure; hold on;
xlabel('Angles'); ylabel('Count');
histogram(a,linspace(0,2*pi,6));
set(gca,'FontSize',fontSize);
drawnow;

%%
% Visualization

%Create circle coordinates to visualize circle curve
t=linspace(0,2*pi,100)';
vc=[cos(t) sin(t)];
N=[cos(a) sin(a)];

cFigure; hold on;
hp1=plotV(vc,'b-','LineWidth',lineWidth);
hp2=plotV(N,'k.','MarkerSize',markerSize);
axis tight; axis equal; box on; grid on;
view(2);
set(gca,'FontSize',fontSize);
legend([hp1 hp2],{'Circle boundary','Uniformly distributed points on circle'},'Location','NorthOutside');
drawnow;

%%
%
% <<gibbVerySmall.gif>>
%
% _*GIBBON*_
% <www.gibboncode.org>
%
% _Kevin Mattheus Moerman_, <gibbon.toolbox@gmail.com>
%%
% _*GIBBON footer text*_
%
% License: <https://github.com/gibbonCode/GIBBON/blob/master/LICENSE>
%
% GIBBON: The Geometry and Image-based Bioengineering add-On. A toolbox for
% image segmentation, image-based modeling, meshing, and finite element
% analysis.
%
% Copyright (C) 2006-2022 Kevin Mattheus Moerman and the GIBBON contributors
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program.  If not, see <http://www.gnu.org/licenses/>.

author: gibbonCode

repo: GIBBON

save_path: github-repos/MATLAB/gibbonCode-GIBBON


text:
%MDL_IR140 Create model of the ABB IRB 140 manipulator
%
%      mdl_irb140_mod
%
% Script creates the workspace variable irb which describes the
% kinematic characteristics of an ABB IRB 140 manipulator using
% modified DH conventions.
%
% Also define the workspace vectors:
%   qz         zero joint angle configuration
%
% Reference::
% - ABB IRB 140 data sheet
% - "THE MODELING OF A SIX DEGREE-OF-FREEDOM INDUSTRIAL ROBOT FOR
%   THE PURPOSE OF EFFICIENT PATH PLANNING"
%   Master of Science Thesis, Penn State U, May 2009
%   Tyler Carter
%
% See also SerialLink, mdl_irb140, mdl_puma560, mdl_stanford, mdl_twolink.
%
% Notes::
% - SI units of metres are used.
% - The tool frame is in the centre of the tool flange.
% - Zero angle configuration has the upper arm vertical and lower arm
%   horizontal.

% MODEL: ABB, IRB140, 6DOF, modified_DH

% Reference::

% Copyright (C) 1993-2015, by Peter I. Corke
%
% This file is part of The Robotics Toolbox for MATLAB (RTB).
%
% RTB is free software: you can redistribute it and/or modify
% it under the terms of the GNU Lesser General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% RTB 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 Lesser General Public License for more details.
%
% You should have received a copy of the GNU Leser General Public License
% along with RTB.  If not, see <http://www.gnu.org/licenses/>.
%
% http://www.petercorke.com

clear L

% joint angle limits from
% A combined optimization method for solving the inverse kinematics problem...
% Wang & Chen
% IEEE Trans. RA 7(4) 1991 pp 489-
L(1) = Revolute('d', 0.352, 'a', 0, 'alpha', 0, 'offset', 0, 'modified');
L(2) = Revolute('d', 0, 'a', 0.070, 'alpha', pi/2, 'offset', 0, 'modified');
L(3) = Revolute('d', 0, 'a', 0.360, 'alpha', 0, 'offset', 0, 'modified');
L(4) = Revolute('d', 0.380, 'a', 0, 'alpha', pi/2, 'offset', 0, 'modified');
L(5) = Revolute('d', 0, 'a', 0, 'alpha', -pi/2, 'offset', 0, 'modified');
L(6) = Revolute('d', 0, 'a', 0, 'alpha', pi/2, 'offset', 0, 'modified');

L(1).m = 34655.36e-3;
L(1).r = [27.87 43.12 -89.03]*1e-3;
L(1).I = [
    512052539.74 1361335.88 51305020.72
    1361335.88 464074688.59 70335556.04
    51305020.72 70335556.04 462745526.12]*1e-9;

L(2).m = 15994.59e-3;
L(2).r = [ 198.29 9.73 92.43]*1e03;
L(2).I = [
    94817914.40 -3859712.77 37932017.01
    -3859712.77 328604163.24 -1088970.86
    37932017.01 -1088970.86 277463004.88]*1e-9;

L(3).m = 20862.05e-3;
L(3).r = [ -4.56 -79.96 -5.86];
L(3).I = [
    500060915.95 -1863252.17 934875.78
    -1863252.17 75152670.69 -15204130.09
    934875.78 -15204130.09 515424754.34]*1e-9;

irb = SerialLink(L, 'name', 'IRB 140', ...
    'manufacturer', 'ABB', 'comment', 'modified DH');

%
% some useful poses
%
qz = [0 0 0 0 0 0]; % zero angles, L shaped pose

clear L

author: Allopart

repo: rbpf-gmapping


text:
%% Image Processing for Microchannel Flow experiment
% Prototype code:
% Using images taken in the experiment:
%
% 1st image fluid flow: 20 mu L/min
% 2st image fluid flow: 10 mu L/min
%
% Microchannel 1: 1808.bmp & 1813.bmp
% Microchannel 2: 1824.bmp & 1828.bmp
% Microchannel 3: 1834.bmp & 1838.bmp
% Microchannel 4: 1843.bmp & 1847.bmp
% Microchannel 5: 1855.bmp & 1860.bmp

target = {'1808.bmp' '1813.bmp'...
    '1824.bmp' '1828.bmp' ...
    '1834.bmp' '1838.bmp' ...
    '1843.bmp' '1847.bmp' ...
    '1855.bmp' '1860.bmp'};
%or
number = [1808 1813 1824 1828 1834 1838 1843 1847 1855 1860];

%Pix_value = [0.31 0.31 0.31 0.31 0.31 0.31 0.31 0.31 0.31 0.31];

%% Load images
name = strcat(num2str(number(1)),'.bmp');
image = imread(name);

%% Apply filter
h = fspecial('unsharp');
image2 = imfilter(image,h); % apply X filter

%% Convert to gray scale
image3 = rgb2gray(image); % conver Original to gray scales
image4 = rgb2gray(image2); % conver Filtered to gray scales

%% Create image negative
% Original Gray
image5 = double(image3);
scale_image = 1/max(image5(:)); % scale_image = 1/255
neg_image5 = 1-image5*scale_image;

% Filtered Gray
image6 = double(image4);
scale_image = 1/max(image6(:)); % scale_image = 1/255
neg_image6 = 1-image6*scale_image;

%% Remove values below an specific Pix_value
Pix_value = 0.31;

[n,m,p] = size(neg_image5);
for k = 1:p
    for j = 1:n;
        for i = 1:m;
            if neg_image5(j,i,k) >= Pix_value
                neg_image5(j,i,k) = 0;
            else
                % do nothing
            end
        end
    end
end
[n,m,p] = size(neg_image6);
for k = 1:p
    for j = 1:n;
        for i = 1:m;
            if neg_image6(j,i,k) >= Pix_value
                neg_image6(j,i,k) = 0;
            else
                % do nothing
            end
        end
    end
end

%% Plot pictures
figure(1);
subplot(2,3,1); imshow(image); title('Original');
subplot(2,3,4); imshow(image2); title('Filtered Image');
subplot(2,3,2); imshow(image3); title('Gray Image with filter');
subplot(2,3,5); imshow(image4); title('Gray Image with out filter');
subplot(2,3,3); imshow(neg_image5); title('Original, filtered an processed');
subplot(2,3,6); imshow(neg_image6); title('negative of the filtered and processed');

%% Save gray_imageX
name2 = strcat(num2str(number(1)),'_gray.bmp');
imwrite(image4,name2,'bmp');

%% Save neg_imageX
name2 = strcat(num2str(number(1)),'_neg.bmp');
imwrite(neg_image6,name2,'bmp');

%% Compute Mixing Index
I = neg_image6;      % Use values in neg_image6 for the difusion analysis.
I_mean = mean(I(:)); % Find the average of the image intensity values.
x = find(I);         % find indices of non-zero values.
N = length(x);       % Total number of non-zero values.

Mix_index = 1-(1/I_mean)*sqrt(sum(sum((I - I_mean).^2))/N);

% Now that I sure what I want to do I'll create a function to evaluate
% automatically data picture.

repo: Aero-matlab


text:
function L = gaussianNoiseLogLikelihood(noise, mu, varsigma, y)

% GAUSSIANNOISELOGLIKELIHOOD Log likelihood of the data under the GAUSSIAN noise model.
% FORMAT
% DESC returns the log likelihood of a data set under the  Gaussian noise model.
% ARG noise : the noise structure for which the log likelihood is required.
% ARG mu : input mean locations for the log likelihood.
% ARG varSigma : input variance locations for the log likelihood.
% ARG y : target locations for the log likelihood.
%
% SEEALSO : gaussianNoiseParamInit, gaussianNoiseLikelihood, noiseLogLikelihood
%
% COPYRIGHT : Neil D. Lawrence, 2004, 2005

% NOISE

N = size(mu, 1);
D = size(mu, 2);
varsigma = varsigma + noise.sigma2;
for i = 1:D
  mu(:, i) = mu(:, i) + noise.bias(i);
end
arg = (y - mu);
arg = arg.*arg./varsigma;

L = - 0.5*sum(sum(log(varsigma))) ...
    - 0.5*sum(sum(arg)) ...
    - 0.5*N*D*log(2*pi);

author: SheffieldML

repo: GPmat

save_path: github-repos/MATLAB/SheffieldML-GPmat


text:
%%
%
% Efficient (hopefully) softmax implementation.
% Return normalized probs as well as scores (numerators in log domain) & norms.
% Note that scores & norms are subtracted/scaled by a constant factor.
% If mask exists, mask out probs.
%
% Thang Luong @ 2015, <lmthang@stanford.edu>
% Hieu Pham @ 2015, <hyhieu@cs.stanford.edu>
%
%%
function [probs, scores, norms] = softmax(raw, varargin)
  % raw: numClasses * batchSize
  mx = max(raw, [], 1);
  scores = bsxfun(@minus, raw, mx); % subtract max elements
  probs = exp(scores); % unnormalized probs
  % TODO: use two-dimensional mask
  norms = sum(probs, 1); % normalization factors
  if length(varargin)==1
    mask = varargin{1};
    scores = bsxfun(@times, scores, mask);
    probs = bsxfun(@times, probs, mask./norms); % normalize and zero out at masked positions
  else
    probs = bsxfun(@rdivide, probs, norms); % normalized probs
  end
end

author: lmthang