Search code examples
arraysdm-script

Array of X- and Y-coordinates - How to store data arrays in scripts?


I have an image of atomic columns and I want to store the X- and Y-coordinates of maximum value of each atomic column but I don't know how to write the script to store bunch of data as an array. Please help me.


Solution

  • I am not sure I unstand the question, but if you are just looking to store multiple values in an "array" then you just need to recognize that any 2D image already is an array. If you want to store n XY-pair values, then you can simple create a [n x 2] image and store the values there. Some example:

    number n = 30       // number of pairs
    image data := Realimage( "Data Array", 4, 2 , n )
    
    for( number i = 0 ; i < n ; i++ )
    {
        number xValue = i * 10                              // just something
        number yValue = xValue * sin( xValue / 100 * PI() )     // just something
        data.SetPixel(0, i, xValue )                // Set X at position i (first column)
        data.SetPixel(1, i, YValue )                // Set Y at position i (second column)
    }
    
    data.ShowImage()
    
    // You may want to display the image as "Spreadsheet". (Type 7)
    data.ImageGetImageDisplay(0).ImageDisplayChangeDisplayType(7)
    
    // And you may want to label the columns
    data.ImageGetImageDisplay(0).SpreadSheetImageDisplaySetColumnLabel( 0, "X values" )
    data.ImageGetImageDisplay(0).SpreadSheetImageDisplaySetColumnLabel( 1, "Y values" )
    

    Image displayed as spread-sheet

    You don't have to use SetPixel(). You can also set pixel values by indexing the position.

     data[0, i] = xValue // Same as: data.SetPixel( 0, i, xValue )