SRL Archive - Research & Development Lounge

how do you setlength of a matrix?


Feroc1ty

2019-03-14 22:24:26

exactly as title states, i understand you have to setlength of all arrays, but how do you set length of a matrix? a t2d array… is it same function and it will set length for both the arrays [y][x], or do i have to do it individually somehow? my [x] will be twice the size of [y] so how do i approach this?

Citrus

2019-03-14 23:33:22

You just iterate through each row:

procedure Test();
const
ROWS = 3;
COLS = 6;
var
i: Int32;
Matrix: T2DIntegerArray; //or Array of Array of Int32;
begin
SetLength(Matrix, ROWS);
for i := 0 to High(Matrix) do
SetLength(Matrix[i], COLS);
end;
The result is a 3x6 matrix.

I think you can switch rows and columns as long as you keep track of which system you're using.

Feroc1ty

2019-03-14 23:58:42

so setlength (var) sets length of first array and setlength (var[x]) sets length of the 2nd array of array x?

beautiful, didnt get the results i wanted but im gonna fuck around with it, just tested it out and worked perfectly, thank you for such a quick response

Olly

2019-03-15 11:39:38

From: Citrus
You just iterate through each row:

procedure Test();
const
ROWS = 3;
COLS = 6;
var
i: Int32;
Matrix: T2DIntegerArray; //or Array of Array of Int32;
begin
SetLength(Matrix, ROWS);
for i := 0 to High(Matrix) do
SetLength(Matrix[i], COLS);
end;
The result is a 3x6 matrix.

I think you can switch rows and columns as long as you keep track of which system you're using.


SetLength does this internally. It will accept a parameter for each dimension.

SetLength(Matrix, 3, 6);

Feroc1ty

2019-03-31 00:22:10

Awesome, thats much easier.