RobotStudio event

Is it possible to copy values from two dimension array's row to one dimension array easily?

Hi,

For simplified example, there's two arrays:
array1{3,3}:=[[1,2,3],[4,5,6],[7,8,9]];
array2{3};

Is it possible to copy values from array1, lets say row 2, to array2 easily? Only way to do this which i've found so far is doing it one value at a time:
array2{1}:=array1{2,1};
array2{2}:=array1{2,2};
array2{3}:=array1{2,3};

doing it one by one isn't really an option with my full scale project :#

Thanks for help!
-Jeppe
Tagged:

Best Answers

Answers

  • Thanks soup, i'll probably use your second example's idea in my project.
  • soup
    soup ✭✭✭
    No problem! Good luck!
  • soup
    soup ✭✭✭
    Someone asked privately -- here's a loop within a loop example:

    MODULE mArrayLoopExample
      
        CONST num In1{5,3}:=[[1,2,3],[4,5,6],[7,8,9],[10,11,12],[13,14,15]];
       
        PERS num Out1{3}:=[0,0,0];
        PERS num Out2{3}:=[0,0,0];
        PERS num Out3{3}:=[0,0,0];
        PERS num Out4{3}:=[0,0,0];
        PERS num Out5{3}:=[0,0,0];

        PROC ArrayMain()
            ArrayLoop In1, "Out";
            Stop;
            ArrayZero In1, "Out";
        ENDPROC
      
        PROC ArrayLoop(num InputArray{*,*}, string OutputArrayName)
            VAR num tempArray{3};
            FOR j FROM 1 TO Dim(InputArray,1) DO
                GetDataVal OutputArrayName+NumToStr(j,0),tempArray;
                FOR i FROM 1 TO Dim(InputArray,2) DO
                    tempArray{i}:=InputArray{j,i};
                ENDFOR
                SetDataVal OutputArrayName+NumToStr(j,0),tempArray;
            ENDFOR
        ENDPROC
       
        PROC ArrayZero(num InputArray{*,*}, string OutputArrayName)
            VAR num tempArray{3};
            FOR j FROM 1 TO Dim(InputArray,2) DO
                tempArray{j}:=0;
            ENDFOR
            FOR j FROM 1 TO Dim(InputArray,1) DO
                SetDataVal OutputArrayName+NumToStr(j,0),tempArray;
            ENDFOR
        ENDPROC
      
    ENDMODULE