Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Elusive Problem with Arrays

For the life of me I can't figure out what it wrong with a user-defined
function I am developing. The problem seems to be in the calculation of
"Distance" from elements of the arrays.

I'm also having problem transfering the ranges to the arrays when the
number of rows is large (~6000).

Any assistance would be greatly appreciated.

Thank you in advance,
Dave

Function IDW(rngX As Range, rngY As Range, rngXData As Range, rngYData
As Range, rngData As Range, Power as Double)
' Fill arrays by assigning ranges to variant variables
varX = rngX
varY = rngY
varXData = rngXData
varYData = rngYData
varData = rngData

NPoints = Application.Count(rngX)
NData = Application.Count(rngXData)
ReDim arrResult(NPoints)

For i = 1 To NPoints
For j = 1 To NData
Distance = Sqr((varX(i) - varXData(j)) ^ 2 _
+ (varY(i) - varYData(j)) ^ 2)
SumDataWeights = SumDataWeights + varData(j) / Distance ^
Power
SumDistWeights = SumDistWeights + 1 / Distance ^ Power
Next j
arrResult(i) = SumDataWeights / SumDistWeights
Next i
IDW = arrResult
End Function

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Elusive Problem with Arrays

This shouldn't work with any size range.

varX = Range("A1:A10")

is a two dimensional array of size varX(1 to 10, 1 to 1)

similar for all your other arrays.

--
Regards,
Tom Ogilvy



wrote in message
ups.com...
For the life of me I can't figure out what it wrong with a user-defined
function I am developing. The problem seems to be in the calculation of
"Distance" from elements of the arrays.

I'm also having problem transfering the ranges to the arrays when the
number of rows is large (~6000).

Any assistance would be greatly appreciated.

Thank you in advance,
Dave

Function IDW(rngX As Range, rngY As Range, rngXData As Range, rngYData
As Range, rngData As Range, Power as Double)
' Fill arrays by assigning ranges to variant variables
varX = rngX
varY = rngY
varXData = rngXData
varYData = rngYData
varData = rngData

NPoints = Application.Count(rngX)
NData = Application.Count(rngXData)
ReDim arrResult(NPoints)

For i = 1 To NPoints
For j = 1 To NData
Distance = Sqr((varX(i) - varXData(j)) ^ 2 _
+ (varY(i) - varYData(j)) ^ 2)
SumDataWeights = SumDataWeights + varData(j) / Distance ^
Power
SumDistWeights = SumDistWeights + 1 / Distance ^ Power
Next j
arrResult(i) = SumDataWeights / SumDistWeights
Next i
IDW = arrResult
End Function



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Elusive Problem with Arrays

Thanks for your quick response. Is their a way to read a range into a
variant as a one dimensional array?

Or should I loop through the cells in the range to fill the array? What
impact will this have on the speed of filling the arrays.

Thank you,
Dave

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default Elusive Problem with Arrays

You could loop through the two dimensional arrays something like this:

Distance = Sqr((varX(i, 1) - varXData(j, 1)) ^ 2 _
+ (varY(i, 1) - varYData(j, 1)) ^ 2)
SumDataWeights = SumDataWeights + varData(j, 1) / Distance ^ Power


Hope this helps
Rowan

" wrote:

Thanks for your quick response. Is their a way to read a range into a
variant as a one dimensional array?

Or should I loop through the cells in the range to fill the array? What
impact will this have on the speed of filling the arrays.

Thank you,
Dave


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
Use of arrays Dave F Excel Worksheet Functions 0 November 30th 06 04:26 PM
Problem with SUMPRODUCT and Arrays [email protected] Excel Worksheet Functions 2 January 13th 06 09:55 PM
Problem with plotting a chart when using arrays as Values and Xvalues [email protected] Charts and Charting in Excel 3 August 19th 05 09:05 PM
Arrays [email protected] Setting up and Configuration of Excel 3 February 18th 05 02:43 AM
arrays in arrays jacob Excel Programming 4 August 29th 04 08:40 PM


All times are GMT +1. The time now is 10:23 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"