i just started to use Mathematica and I`m completely new to programming. So i'm some kind of noob in the purest form..

I'm trying to transform a coordinate system into a different one. I'm using M1 as a kind of map to get the position of the elements I'm looking for in the other matrix named CorrectionM. Mathematically it`s just an easy transformation of coordinates by using "addition"

I've programmed a chain of operations starting with a simple list with 3 elements (Input1). This operations works fine for just one list (Output of CorrectedData is correct), but I cant expand it on a matrix-like-List List2 (which is my main intention). I've tried to manipulate the whole List2, but the FirstPosition cant be applied on a list directly.

Is there a function which imports every row of List2 in my Input1? And is there a way to sumarize the output of the last operation (CorrectedData) in a list again? I've tried to use Map, Table or Apply to do the iteration, but I'm just clueless. :)


(* List2: {NumberofCoord, X-Coordinate, Y-Coordinate} *)
List2 = {{50, 100, 50}, {20, 100, 50}, {30, 100, 50}};

Input1 = {50, 100, 50};

(*Extract First number of Input->Number of CoordinateSystem in M1*)

NumberofCoord = Input1[[1]]
(*Identify position of coordinatesystem in Matrix M1*)

IdentifyPosition = FirstPosition[M1, NumberofCoord]

{5, 10}

Correction = CorrectionM[[IdentifyPosition[[1]], IdentifyPosition[[2]]]]

{9000, 5000}

(* Addition Bildkoordinaten und des Korrekturfaktors *)
CorrectedData = {Input1[[2]], Input1[[3]]} + Correction

{9100, 5050}


enter image description here

  • 5
    $\begingroup$ It is strongly recommented to post your code instead of a picture, so that everyone can try some tests $\endgroup$
    – ZaMoC
    Apr 13, 2019 at 13:20

2 Answers 2



data = {{50, 100, 50}, {20, 100, 50}, {30, 100, 50}};
m1 = ArrayReshape[Range[100], {10, 10}];
corrections = Table[{(j - 1) 1000, 10000 - i 1000}, {i, 10}, {j, 10}];

we need to write a function that will take a triple as its input and carry out your calculation on that triple and return the result. Then we can map that function over the list data.

Because of Mathematica's powerful pattern matching capabilities can be applied to destructuring arguments, the needed function can be very easily written. It is just a one-liner.

correct[{i_, x_, y_}] := {x, y} + Extract[corrections, FirstPosition[m1, i]]

Now we test to see if correct can carry out your calculation.


{9100, 5050}

Looks good, so let's do the mapping.

correct /@ data

{{9100, 5050}, {9100, 8050}, {9100, 7050}}

Since you say you are completely new to programming, perhaps that one-liner, although elegant, is a little hard for you to interpret. Here is a step-by-step approach which might more to taste at this point in your experience.

correct[datum_] :=
  Module[{i, x, y, pos},
    {i, x, y} = datum;
    pos = FirstPosition[m1, i];
    {x, y} + Extract[corrections, pos]]
  • $\begingroup$ Works fine! Thank you very much! :) $\endgroup$
    – stoffi3000
    Apr 14, 2019 at 19:20
  • $\begingroup$ @stoffi3000. I'm glad you find my answer useful. Please consider accepting it. You can do that by clicking on the check mark that appears on the left of the answer below the down arrow. $\endgroup$
    – m_goldberg
    Apr 14, 2019 at 19:28

It would be much easier if you hadn't post just a picture but the actual code
Can you try this and tell me if it works for every element on List2?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.