# Can I use map () in a loop?

I have a piece of code and I want to use the map() in order to have the last column of the array with values between 5 and 60. 5 will equal to the minimum value and 60 to the maximum, and the numbers in the middle they will follow a linear relationship with the previous rule.
My question is, how can I transform all the numbers of the last column of the array using map()? I was thinking in using a loop, first I have found the maximum and minimum values of the column and now I don’t know how to transform the rest. I use the float a later.

``````int max = cities[0][2];
int min = cities[0][2];

for (int j=1; j<cities.length; j++){
if (cities[j][2] < min){
min=cities[j][2];
}
if(cities[j][2] > max){
max=cities[j][2];
}

float a= map(j, min, max, 5, 60);
...
}
``````

Do you mean something like this?

``````void setup() {
size(200, 200);
}

void draw() {
noFill();
int[] vals = {1, 77, 100, 20, 56, 32, 88};
for (int v: vals) {
circle(width / 2, height / 2, map(v, 1, 100, 5, 60));
}
}
``````

Resulting image:

Edited to correct a typographical error.

1 Like