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

jeppe
✭
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};
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:
0
Best Answers
-
Here's a basic example:MODULE mArrayLoopExample
CONST num array1{3,3}:=[[1,2,3],[4,5,6],[7,8,9]];
PERS num array2{3}:=[0,0,0];
PROC ArrayLoopExample()
FOR i FROM 1 TO Dim(array1,2) DO
array2{i}:=array1{2,i};
ENDFOR
ENDPROC
ENDMODULE
5 -
Taking the example a little further:MODULE mArrayLoopExample
CONST num array1{3,3}:=[[1,2,3],[4,5,6],[7,8,9]];
PERS num array2{3}:=[0,0,0];
PROC ArrayLoopExampleCall()
ArrayLoopExample array1, array2;
ENDPROC
PROC ArrayLoopExample(num InputArray{*,*}, INOUT num OutputArray{*})
FOR i FROM 1 TO Dim(InputArray,2) DO
OutputArray{i}:=InputArray{2,i};
ENDFOR
ENDPROC
ENDMODULE
5
Answers
-
Thanks soup, i'll probably use your second example's idea in my project.
0 -
No problem! Good luck!
0 -
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
0
Categories
- All Categories
- 5.5K RobotStudio
- 398 UpFeed
- 19 Tutorials
- 13 RobotApps
- 299 PowerPacs
- 405 RobotStudio S4
- 1.8K Developer Tools
- 250 ScreenMaker
- 2.8K Robot Controller
- 323 IRC5
- 63 OmniCore
- 7 RCS (Realistic Controller Simulation)
- 812 RAPID Programming
- 5 AppStudio
- 3 RobotStudio AR Viewer
- 19 Wizard Easy Programming
- 105 Collaborative Robots
- 5 Job listings