Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Redim with string input (MATLAB Zeros function)
I am trying to create a function that mimics MATLAB's zeros function where it
creates a variable of zeros (see http://www.mathworks.com/access/help...ref/zeros.html) To do this, I use a Parameter Array to obtain the dimensions and sizes. For example, to get a 2 X 2 array of zeros, you'd use the syntax "=matZeros(2,2)". I'm trying to build a string based on the ParamArray, but that doesn't seem to work. The code is below. Can anyone suggest a workaround? Thanks, Matthew Pfluger =============================================== Private Function matZeros(ParamArray vArr() As Variant) As Variant Dim tempVar As Variant If UBound(vArr) - LBound(vArr) = 0 Then GoTo errorhandler Dim sDimensions As String Dim iInc As Integer sDimensions = "" For iInc = LBound(vArr) To UBound(vArr) If IsNumeric(vArr(iInc)) Then sDimensions = sDimensions + ", 1 to " & vArr(iInc) End If Next ' Remove leading comma If Left(sDimensions, 1) = "," Then sDimensions = Right(sDimensions, Len(sDimensions) - 2) ' Create array based on data type (if applicable) If Not (IsNumeric(UBound(vArr))) Then Select Case UBound(vArr()) Case "Single" ReDim tempVar(sDimensions) As Single Case "Double" ReDim tempVar(sDimensions) As Double Case "Integer" ReDim tempVar(sDimensions) As Integer Case "Long" ReDim tempVar(sDimensions) As Long Case Else GoTo errorhandler End Select Else ' default to double if data type omitted ReDim tempVar(sDimensions) As Double End If matZeros = tempVar Exit Function errorhandler: Err.Raise 15 End Function =============================================== |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
how can ý call matlab function from matlab to excel | Excel Discussion (Misc queries) | |||
ReDim string in loop | Excel Programming | |||
Keep leading zeros in a string array | Excel Programming | |||
how do i do an inline function like in matlab | Excel Worksheet Functions | |||
Removing Leading Zeros from a String | Excel Programming |