We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › how to store value from an array
Page Index Toggle Pages: 1
how to store value from an array (Read 829 times)
how to store value from an array
Mar 1st, 2006, 4:35pm
 
hello,
i have a function like this:

float Value (float maxValue){
 maxValue=0;
 float Array[]={.........};
 for ( int i = 0; i < Array.length; i++){
   if(Array[i]>maxValue)
   {
    maxValue=Array[i];  
   }
 }
 return maxValue;
}

Array refresh at each frame and i take the max value from it. How i can store this values for find the average value?

thanks
Re: how to store value from an array
Reply #1 - Mar 1st, 2006, 5:28pm
 
Heres is the basic logic required, if I am understanding your question right...

//declare an array of type float
float[] maxValues;
float average, sum;

//in the setup assign a values variables
maxValues = new float[numberOfValues];
average = 0;
sum = 0;

//in the loop assign a value to each index in the "maxValues" array

for(int i = 0; i < maxValues.length) {
 maxValues[i] = maxValue;
}

//to calculate the average sum all the values inside the maxValues array

for(int i = 0; i < maxValues.length) {
 sum += maxValues[i];
}

average = sum/maxValues.length



Re: how to store value from an array
Reply #2 - Mar 1st, 2006, 6:32pm
 
sorry,
perhaps I didn't explain much good, because my english is very bad.

the array i have, is LiveInput.getSpectrum that it is generated by pitaru.sonia. from it, each frame, i take the max value, but, at the same time i want to compute the average with the previous max value.

i am new with processing, and with english too.
I hope that this time i have explained better the question.

Re: how to store value from an array
Reply #3 - Mar 1st, 2006, 7:24pm
 
still the same logic applies. you would store each max value in the "maxValue" array once the max has been calculated.
Re: how to store value from an array
Reply #4 - Mar 2nd, 2006, 12:38am
 
thanks,
I have not still understood how it works. but, I will work in these days to understand it. I will say you of my improvements
Page Index Toggle Pages: 1