Home > compute > feBuildSparseBlockDiag.m

feBuildSparseBlockDiag

PURPOSE ^

Build a sparse block-diagonal matrix with ones in all filled elements.

SYNOPSIS ^

function A = feBuildSparseBlockDiag(nBvecs,nVoxels, values)

DESCRIPTION ^

  Build a sparse block-diagonal matrix with ones in all filled elements.

       A = feBuildSparseBlockDiag(nBvecs,nVoxels, [values]);

  This is used to build the matrix used to represent the isotropic
  component contributions to the diffusion data in each voxel.

  INPUTS:
  nBvecs  -  How many directions in your DWI data.
  nVoxels -  How many voxels in the ROI.
  values  -  Either a value for every voxel (column, size(values) = nVoxels) OR
             one value for all the voxels, e.g., 0.5

  OUTPUTS:
  A       - A block-diagonal matrix.
            In each column, there are nBvecs filled rows. These are always filled
            with either a '1' OR a value (if passed in). The location of the
            non-zero elements in each column is:
            col * nBvecs + 1: (col + 1) * nBvecs

  EXAMPLE:
    >> A = feBuildSparseBlockDiag(3,3)
       A = (1,1) 1
           (2,1) 1
           (3,1) 1
           (4,2) 1
           (5,2) 1
           (6,2) 1
           (7,3) 1
           (8,3) 1
           (9,3) 1

 Copyright (2013-2014), Franco Pestilli, Stanford University, pestillifranco@gmail.com.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function A = feBuildSparseBlockDiag(nBvecs,nVoxels, values)
0002 %  Build a sparse block-diagonal matrix with ones in all filled elements.
0003 %
0004 %       A = feBuildSparseBlockDiag(nBvecs,nVoxels, [values]);
0005 %
0006 %  This is used to build the matrix used to represent the isotropic
0007 %  component contributions to the diffusion data in each voxel.
0008 %
0009 %  INPUTS:
0010 %  nBvecs  -  How many directions in your DWI data.
0011 %  nVoxels -  How many voxels in the ROI.
0012 %  values  -  Either a value for every voxel (column, size(values) = nVoxels) OR
0013 %             one value for all the voxels, e.g., 0.5
0014 %
0015 %  OUTPUTS:
0016 %  A       - A block-diagonal matrix.
0017 %            In each column, there are nBvecs filled rows. These are always filled
0018 %            with either a '1' OR a value (if passed in). The location of the
0019 %            non-zero elements in each column is:
0020 %            col * nBvecs + 1: (col + 1) * nBvecs
0021 %
0022 %  EXAMPLE:
0023 %    >> A = feBuildSparseBlockDiag(3,3)
0024 %       A = (1,1) 1
0025 %           (2,1) 1
0026 %           (3,1) 1
0027 %           (4,2) 1
0028 %           (5,2) 1
0029 %           (6,2) 1
0030 %           (7,3) 1
0031 %           (8,3) 1
0032 %           (9,3) 1
0033 %
0034 % Copyright (2013-2014), Franco Pestilli, Stanford University, pestillifranco@gmail.com.
0035 
0036 if notDefined('values'),values = ones(1,nVoxels);end
0037 
0038 % If only one value is passed in (the same value for all voxels)
0039 % We replicate it.
0040 if (length(values) == 1), values = values .* ones(1,nVoxels);end
0041 
0042 idx_rows    = 1:nBvecs * nVoxels;
0043 idx_columns = reshape(repmat(1:nVoxels,nBvecs,1), 1, nBvecs * nVoxels);
0044 A           = sparse(idx_rows, idx_columns, ones(nBvecs, nVoxels) .* ...
0045                                             repmat(values,nBvecs,1));
0046 
0047 end

Generated on Wed 16-Jul-2014 19:56:13 by m2html © 2005