Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 130
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how can ý call matlab function from matlab to excel gurhan Excel Discussion (Misc queries) 0 November 29th 06 08:40 AM
ReDim string in loop Arne Hegefors Excel Programming 11 August 23rd 06 01:38 AM
Keep leading zeros in a string array quartz[_2_] Excel Programming 2 May 31st 05 11:51 PM
how do i do an inline function like in matlab jonathon wycherley Excel Worksheet Functions 4 December 11th 04 12:15 AM
Removing Leading Zeros from a String MARTY Excel Programming 16 July 2nd 04 02:11 PM


All times are GMT +1. The time now is 07:20 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"