Location: 12 L Platform 1 model codes @ 9ac5ec0fe3f8 / peripheral_airway / Peripheral_matlab / createSymmTMatrix.m

Author:
aram148 <a.rampadarath@auckland.ac.nz>
Date:
2021-12-17 11:46:34+13:00
Desc:
Added the Matlab 7 airway code
Permanent Source URI:
http://models.cellml.org/workspace/6b0/rawfile/9ac5ec0fe3f8ae60e6020b99146573defeb5a5e9/peripheral_airway/Peripheral_matlab/createSymmTMatrix.m

% A function that will compute the necessary transformation matrix, T,
% that maps all 

% This function will be structured as a recursive function, with the base
% case being the trivial 3-branch case (order 2)

% DATE: 22/02/17
% AUTHOR: Austin Ibarra
% VERSION: 1.0

% == LOG CHANGE == %

function T = createSymmTMatrix(order)
%% Initialise the matrix
numBr = 2^order - 1;
numRows = (numBr - 1)/2;
numCols = (numBr + 1)/2;
V = zeros(numRows,numCols);

%% Perform the looping
numElem = 2;  % Start off with 1/2, when filling out the matrix
count = 0;
row = 1;   % The current row that we are on
i = 1;
while i <= numCols   % loop along the columns

    V(row,i) = 1/numElem;
    count = count + 1;
        
    if i == numCols   
        % Check if we have reached the end of the matrix columns. If yes,
        % then check if we are on the last row, and if we are, then
        % terminate the loop.
        if row == numRows
            break
        else
            % Otherwise, it means that we need to move onto the next row,
            % reset count, and double numElem.
            row = row + 1;
            count = 0;
            i = 1;
            numElem = numElem*2;
        end
    else
        i = i + 1;
    end
    
    if count == numElem
        row = row + 1;   % Move onto the next row
        count = 0;      % Reset count back to zero
    end

end
%% Now, concatenate the matrices together to form T
I = eye((numBr + 1)/2);
ZERO = zeros(numBr,(numBr - 1)/2);
T = cat(2,cat(1,I,V),ZERO);
end