Jump to content

array 2D compare


faustf
 Share

Recommended Posts

hi guys i want compare  a 2D dimentional  array  , i saw some post here  , i try to applicate but ,not  go o_O.... sorry

this is my script

#include <GuiRichEdit.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <MsgBoxConstants.au3>
#include <GuiStatusBar.au3>

Local $aLBuyAndPrice[5][2]
_ArrayDisplay($aLBuyAndPrice, 'primo array')
Local $aLBuyAndPriceTwin[5][2]
$sFill = "29|58.20"
_ArrayAdd($aLBuyAndPriceTwin, $sFill)

_ArrayDisplay($aLBuyAndPriceTwin, 'secondo array')

Local $aL2Diff = _Array2DdifSort($aLBuyAndPrice, $aLBuyAndPriceTwin)
_ArrayDisplay($aL2Diff, 'diff array')



Func _Array2DdifSort($aArrayOne_2D, $aArrayTwo_2D)
    #cs
        For $iI = UBound($aArrayOne_2D) - 1 To 0 Step -1
        For $j = UBound($aArrayTwo_2D) - 1 To 0 Step -1
        If $aArrayOne_2D[$iI][1] = $aArrayTwo_2D[$j][1] Then ;_ArrayDelete($aArray, $iI)
        $aArrayOne_2D[$iI][1] = ""
        EndIf
        Next
        Next
        ;   _ArrayDisplay($aArrayOne_2D) ;after comparison with assigning blanks

        For $iI = UBound($aArrayOne_2D) - 1 To 0 Step -1
        If $aArrayOne_2D[$iI][1] = "" Or $aArrayOne_2D[$iI][1] = "E" Then _ArrayDelete($aArrayOne_2D, $iI)
        Next
        ;   _ArrayDisplay($aArrayOne_2D) ;after deleting blanks and "E"
        Return $aArrayOne_2D
    #ce

    For $i = UBound($aArrayOne_2D) - 1 To 0 Step -1
        For $j = UBound($aArrayTwo_2D) - 1 To 0 Step -1
            If $aArrayOne_2D[$i][1] = $aArrayTwo_2D[$j][1] Or $aArrayOne_2D[$i][1] = "E" Then
                _ArrayDelete($aArrayOne_2D, $i)
                ExitLoop
            EndIf
        Next
    Next

    Return $aArrayOne_2D

EndFunc   ;==>_Array2DdifSort

anyone can help me??

thankz alot

 

Link to comment
Share on other sites

You can open the Array.au3 include file and take a look at _ArraySort  if you're wanting to sort them like you're function says. If you do actually mean compare them, then you'll need to be a bit more specific about what exactly you want to compare in the arrays ;)

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

thankz  i will look , i try to resolve  in this moment with this  solution but  also in this mode not work not return me a value in if

#include <Array.au3>
#include <Color.au3>
#include <GuiRichEdit.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <MsgBoxConstants.au3>
#include <GuiStatusBar.au3>

Local $aLBuyAndPrice[5][2]
_ArrayDisplay($aLBuyAndPrice, 'primo array')
Local $aLBuyAndPriceTwin[5][2]
$sFill = "29|58.20"
_ArrayAdd($aLBuyAndPriceTwin, $sFill)

_ArrayDisplay($aLBuyAndPriceTwin, 'secondo array')

;Local $aL2Diff = _Array2DdifSort($aLBuyAndPrice, $aLBuyAndPriceTwin)
Local $aL2Diff = _de($aLBuyAndPrice, $aLBuyAndPriceTwin)
;Local $aL2Diff = _Array2DdifSortP($aLBuyAndPrice, $aLBuyAndPriceTwin)
_ArrayDisplay($aL2Diff, 'diff array')

Func _de($aArrayOne_2D, $aArrayTwo_2D)
    Local $sLArray1 = _ArrayToString($aArrayOne_2D)
    Local $sLArray2 = _ArrayToString($aArrayTwo_2D)

    If StringCompare($sLArray1, $sLArray2) <> 0 Then
        For $i = 0 To UBound($sLArray2) - 1
            If $sLArray2[$i] <> "" Then
                ConsoleWrite("val " & $sLArray2[$i] & @CRLF)
            EndIf
        Next
    EndIf

EndFunc   ;==>_de

o_O

Link to comment
Share on other sites

how about with an example everyone can use?   Is this close?

#include<array.au3>

local $a[2][3] = [['1','2','3'] , ['4','5','8']]
local $b[2][3] = [['7','8','9'] , ['1',"A","B"]]

;~ _ArrayDisplay($a)
;~ _ArrayDisplay($b)


For $i = 0 to ubound($a) - 1
   For $k = 0 to ubound($a , 2) - 1
      For $j = 0 to ubound($b) - 1
         For $l = 0 to ubound($b , 2) - 1


      If $a[$i][$k] = $b[$j][$l] Then msgbox(0, 'match' , "$a[" & $i & "][" & $k & "]  =  $b[" & $j & "][" & $l & "]")

         Next
      Next
   Next
Next

 

edit:  I had copied a bad character, your above example is now firing.  I will populate mine with similar strings

Edited by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

thankz  your prog work but  ,probably i explain problem not so good .

scenario: you read  a data in real time from sensor  and  return  this  value

valore  34--57,97
valore  61--57,96
valore  61--57,96
valore  34--57,97
valore  34--57,97
valore  61--57,96
valore  61--57,96

i want in real time , if  arrive a first time  34--57.97  print , but  when arrive the second time not print it  in this mode  the list upper  will be 

valore  34--57,97
valore  61--57,96
 

i try with compare  2 array 2D  but when  shift  second  to first   and  in second load  data  like startfirst, it print it  how  is possible remove this bug?

thankz

 

Link to comment
Share on other sites

Maybe this :

#include <Constants.au3>
#include <Array.au3>

Opt ("MustDeclareVars", 1)

Local $aValueRead[0], $sValue
While True
  $sValue = ReadSensor ()
  If @error Then ExitLoop
  _ArraySearch ($aValueRead, $sValue)
  If @error Then _ArrayAdd ($aValueRead, $sValue)
WEnd
_ArrayDisplay ($aValueRead)

;this function needs to be rewritten to get your sensor values
Func ReadSensor ()
  Local Const $aSensor [] = [7, _
    "valore  34--57,97", _
    "valore  61--57,96", _
    "valore  61--57,96", _
    "valore  34--57,97", _
    "valore  34--57,97", _
    "valore  61--57,96", _
    "valore  61--57,96" ]
  Local Static $iInd = 0
  $iInd += 1
  If $iInd > $aSensor[0] Then Return SetError (1)
  Return $aSensor[$iInd]
EndFunc

 

Link to comment
Share on other sites

1 hour ago, faustf said:

why you choice _arraysearch and not arrybinarysearch ?

The reason for this can possibly be found in the remarks of the frequently cited AutoIt-Help ;).

-> _ArraySearch : ... is useful when the array cannot be sorted before the search.

-> _ArrayBinarySearch : When performing a binary search on an array of items, the array (specified column if 2D) MUST be sorted in ASCENDING order before the search is done. Otherwise undefined results will be returned.

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

You don't explain your context well enough.

You get input from a number of data capture devices.  How many devices you're having to deal with is an important information (5 isn't the same as tens of thousands).
You store this data and I expect that there is a device identifier in your input stream (maybe 34 & 61 in your examples).
Along with device ID you also get measure data (I guess it's  57,97 & 57,96 in your examples).
You say "real time" but give no clue about how fast you're obtaining data and how fast you want it processed.
You don't want to store duplicate measurements from the same device.
OK till there.

Now I still have questions to provide a useful, practical answer:
  1) Are you interested in keeping the order of arrival of distinct data from every device (then you need to store precise time of arrival as well)
or
   2) Are you just interested in storing the various distinct measures obtained by each device, independant of the moment they were sampled?
  3) How many distinct measures are you going to collect during the run of the program (dozens, billions)?
  4) Are you processing the data while it accumulates?

For instance, 1) would allow you to represent a graph of the variation of measures (time, value) for each device, but 2) would say nothing about when a pathological measurement occured.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

1 data is not fundamental but if exist why not

2 no

3  1 milion for a day maybe, but  in this milion i have 2/3 duplicate data

4 yes  is  necessary elaborate  in realtime and excluding duplicated data

(the velocity is variable some time  is very fast change digit under seconds  some time  change digit after one minuts)

 

 

 

Link to comment
Share on other sites

Then I would use SQLite to store and retrieve the data, without one second of hesitation.  That will also make later processing the data (statistics or detailed analysis) much easier.

 

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

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

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...