%% $RCSfile: sdspdiag2.tlc,v $ %% $Revision: 1.3 $ %% $Date: 2000/06/15 20:37:39 $ %% %% Copyright 1995-2000 The MathWorks, Inc. %% %% Abstract: Create a matrix from a diagonal or extract the diag from a matrix. %implements sdspdiag2 "C" %% Function: BlockInstanceSetup =============================================== %% %% Abstract: %% Rename the S-Function parameter for easy reference. %% %function BlockInstanceSetup(block, system) void %% % %% %endfunction %% Function: Outputs ========================================================== %% %function Outputs(block, system) Output /* DSP Blockset Matrix Diagonal (%) - % */ %% %assign Diag2Full = 1 %assign Full2Diag = 2 %% %assign INPORT = 0 %assign OUTPORT = 0 %assign mode = LibBlockParameterValue(Mode,0) %assign a_width = CAST("Number",LibBlockInputSignalWidth(0)) %assign o_width = CAST("Number",LibBlockOutputSignalWidth(0)) %assign cplx = LibBlockInputSignalIsComplex(INPORT) != 0 %assign dtype = cplx ? "creal_T" : "real_T" %assign need_copy = (LibBlockInputSignalBufferDstPort(INPORT) != OUTPORT) %% %if need_copy { % *A = %; % *y = %; %if mode == Diag2Full /* Diag2Full */ int_T nc = 0; while (nc++ < %) { int_T nr = 0; while (nr++ < %) { %if !cplx *y++ = (nr == nc) ? *A++ : 0.0; %else if(nr == nc) { *y++ = *A++; } else { y->re = 0.0; (y++)->im = 0.0; } %endif } } %elseif mode == Full2Diag %assign numDims = LibBlockInputSignalNumDimensions(INPORT) %assign dims = LibBlockInputSignalDimensions(INPORT) %assign cols = (numDims == 2) ? dims[1] : 1 %assign rows = dims[0] %if rows < cols %assign Nmin = rows %else %assign Nmin = cols %endif /* Full2Diag */ int_T i = %; while (i-- > 0) { *y++ = *A; A += %; } %endif } %else %% /* Scalar output equals input. No code needed. */ %% %endif %endfunction %% [EOF] sdspdiag2.tlc