# help with performing operations on matrix parts inside a loop

I would like to translate the following code into Mathematica language but am having some trouble doing so:

h1=1;
L1=Array[f,9];
for(i=1,i<4,i++)
{
for(j=1,j<4,j++)
{
q1=Part[SomeMatrix,i,j]
q2=Apart[q1]
f[h1]=q2
h1++
}
}


the aim is to perform 2 operations on each cell of a matrix and then create a new 3X3 matrix out of the predefined array L1.

help will be much appreciated. Thank you in advance

• As a start, try to forget the looping approach completely. Describe what you would like to accomplish (what operation, on what matrix, with what result). Typically you can carry that out with Map, or Table. Commented Feb 22, 2021 at 22:04

Is this what you're trying to accomplish?

Map[Apart, SomeMatrix, {2}]

(* create an example matrix *)
mA = Array[(Subscript[c, #] + Subscript[d, #])/(Subscript[a, #] +
Subscript[b, #]) &, {3, 3}]

(* direct translation *)
h1 = 1;
L1 = Array[f, 9]
For[i = 1, i < 4, i++,
For[j = 1, j < 4, j++, q1 = Part[mA, i, j]; q2 = Apart[q1];
f[h1] = q2; h1++]]
L1

(* better approach *)
Apart /@ Catenate@mA