Rescaling values

Hi,I have an array of values from 0-1 and i want to rescale the values from 0-255.Any ideas?Thank u !Maria
[141 byte] By [mayra] at [2007-9-26 6:40:04]
# 1
The simplest (and perhaps not the best) would be to loop through the array, multiplying as you go. I don't know if there's an easier way with [] arrays.m
wywiwyg at 2007-7-1 15:57:53 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 2
Thank u for replying to me!Do u mean i should multiply each element by 255?CheersMaria
mayra at 2007-7-1 15:57:53 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 3

Something like this should do the trick:

public void scaleArray(double[] anArray, double scaleValue) {

for(int i = 0; i < anArray.length; i++) {

anArray[i] *= scaleValue;

}

}

m

wywiwyg at 2007-7-1 15:57:53 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 4

I have 3 arrays (norm1[], norm2[], norm3[]) that i need to pass into this method in order to rescale them.Will the following code do that?

public void scaleArray(double[] anArray, 255)

{

for(int i = 0; i < anArray.length; i++) {

for(int j = 0; j < anArray.width; j++) {

anArray<i> *= 255; }

}

int new1 []= norm1[].scaleArray;

and the same for the other 2?

Thank u very much

Maria

mayra at 2007-7-1 15:57:53 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 5

public void scaleArray(double[] anArray, int low, int high)

{

for(int i = 0; i < anArray.length; i++) {

for(int j = 0; j < anArray.width; j++) {

anArray<i> = (high-low) * anArray<i> + low;

}

}

}

//...

double[] norm1;

scaleArray(norm1, 0, 255);

trejkaz at 2007-7-1 15:57:53 > top of Java-index,Archived Forums,New To Java Technology Archive...