Milaffyd

Greenhorn

Posts: 3

posted 15 years ago

I have a program that makes use of an extended Vector. This vector stores datapoint objects, each of which contain two double type values: an x and a y. One added function to the Vector allows it to scan itself for x and y maxes, and x and y mins. For some odd reason, it is failing to do this properly and ends up storing values that are not the min nor the max in the data set. I have included the code for the scan. Any takers?

public void dataStats() {

xmax = ((datapoint) this.firstElement()).getx();

xmin = ((datapoint) this.firstElement()).getx();

ymax = ((datapoint) this.firstElement()).gety();

ymin = ((datapoint) this.firstElement()).gety();

Enumeration scan = this.elements();

while (scan.hasMoreElements()) {

datapoint processxy = (datapoint)scan.nextElement();

double y = processxy.gety();

double x = processxy.getx();

xmax = Math.max(x, xmax);

xmin = Math.min(x, xmin);

ymax = Math.max(y, ymax);

ymin = Math.min(y, ymin);

}

}

public void dataStats() {

xmax = ((datapoint) this.firstElement()).getx();

xmin = ((datapoint) this.firstElement()).getx();

ymax = ((datapoint) this.firstElement()).gety();

ymin = ((datapoint) this.firstElement()).gety();

Enumeration scan = this.elements();

while (scan.hasMoreElements()) {

datapoint processxy = (datapoint)scan.nextElement();

double y = processxy.gety();

double x = processxy.getx();

xmax = Math.max(x, xmax);

xmin = Math.min(x, xmin);

ymax = Math.max(y, ymax);

ymin = Math.min(y, ymin);

}

}

Manfred Leonhardt

Ranch Hand

Posts: 1492

Milaffyd

Greenhorn

Posts: 3

posted 15 years ago

Thanks, Manfred.

I tried implementing the good old-fashioned index search via the for loop. The applet still fails to acknowledge the proper maxes and mins. If anything, it seems worse since it's selected a value much less than before for a max. Could it be that some sort of memory error occurring?

http://pubweb.nwu.edu/~eyy830/JavaDev/qrs/qrs.htm

This site is where I post my running applets. Each applet relies on data from its predecessor and performs calculations to get the results you'll see. Hence, why I wonder if it's a memory error from passing vectors repetitively. You'll notice the error if you examine the very last applet panel with a time range between 0 and 1 second. That applet is the only place where I've seen the mistake.

I tried implementing the good old-fashioned index search via the for loop. The applet still fails to acknowledge the proper maxes and mins. If anything, it seems worse since it's selected a value much less than before for a max. Could it be that some sort of memory error occurring?

http://pubweb.nwu.edu/~eyy830/JavaDev/qrs/qrs.htm

This site is where I post my running applets. Each applet relies on data from its predecessor and performs calculations to get the results you'll see. Hence, why I wonder if it's a memory error from passing vectors repetitively. You'll notice the error if you examine the very last applet panel with a time range between 0 and 1 second. That applet is the only place where I've seen the mistake.

Consider Paul's rocket mass heater. |