# Compare two 2D arrays

## Recommended Posts

I'm in search of a "compare two 2D arrays" function which gives me the results of comparison. For example match or no match, or even better: values which don't match.

Background: I'm comparing two INI files for differences. The problem is that the section names are mixed, which means the keys can appear in the first INI file in section A and in the other INI file in section B. So I started to read every section of the first INI file into an 2D array and now I try to compare this array with every section in the second INI file where I read every section into an 2D array, too.

INI file A:

[section A]

A=1

B=2

C=3

D=4

[section B]

A=1

B=5

C=3

D=8

...

INI file B:

[section A]

A=1

B=5

C=3

D=8

[section B]

A=1

B=2

C=3

D=4

...

Is there a predefined function for doing this? I searched the forum but did not find any function which fits my needs.

##### Share on other sites

Rather than have us search the forum again to link to you 2D array compare functions, would you mind posting what you've already found so we don't need to make ourselves redundant?

##### Share on other sites

I just found function _Array2D_ToString, which makes it possible to easily convert the 2D arrays to a string and then compare every string of source array with every string of target array. This leads me into coding loops for comparing the whole INI files. So maybe there is somebody out there who had the same problem and already coded a function for this. Or maybe you skilled guys know a way better strategy for comparing two INI files?

.

.

##### Share on other sites

Nicely edited posts.

What do you have so far?

##### Share on other sites

I personally think you're looking at the problem too narrow minded, and there is a solution that can be applied on a bigger level. An example of this is would be writing the ini file in the correct order.

Although, that is your call to make.

I have written this before for a OCR program I was making:

```Func _CompareArray(\$pPixel1, \$pPixel2, \$pAccuracy = 0.95)
Local \$minX = _Min(UBound(\$pPixel1,1), UBound(\$pPixel2,1))
Local \$minY = _Min(UBound(\$pPixel1,2), UBound(\$pPixel2,2))

Local \$iDiff = 0
Local \$iTotal = (\$minX) * (\$minY)

For \$x = 0 to \$minX-1
For \$y = 0 to \$minY-1
If ( \$pPixel1[\$x][\$y] <> \$pPixel2[\$x][\$y] ) Then
\$iDiff += 1
EndIf
Next
Next

\$a = ( \$iDiff / \$iTotal )
If ( \$a < (1-\$pAccuracy) ) Then ; Returns true based on a 95% match ( parameter \$pAccuracy )
Return 1
Else
Return 0
EndIf
EndFunc```

For background information see this thread: http://www.autoitscript.com/forum/index.ph...t=0&start=0

Edit: _Min is declared in Math.au3

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account