I have been working on this program for WEEKS now, and I have gotten nowhere... I just can't seem to figure it out.
So the basic idea is to plot a dataset of car information (kind of like 'objects', each has many attributes like MPG cylinders, etc.). The information is stored in an excel file.
This information is read into a 2D array, and the subsequent attributes (like MPG) are read into their own 1D arrays.
There are a good many 'cars' in the data set... the idea is that they are displayed using pixels (etc) in something that looks like a 2D array of scatterplots. (see image below)
-------
WHAT I AM STRUGGLING WITH:
I have to allow the user to select a data point with the RIGHT-MOUSE BUTTON - which I have done successfully. I can get the program to print out the coordinates.
However, the requirement is to print out the actual value stored in the original 2D array (pretty sure) - to basically output the MPG information for that particular point.
What I don't understand is how to go from a normalized array... back to the 2D array in the beginning.
I would SINCERELY appreciate any help that anybody could offer, as I am at a loss... and have much more programming to do that is being severely neglected.
I will post the code below, however, it's pretty lengthy...
thanks for your time!
PFont f;
Cell[][] grid;
int cols = 10;
int rows = 10;
String[][] carData = new String[407][10]; //2D array to store the dataset.
float[] MPG = new float[407]; //1D array for MPG.
float[] Cylinder = new float[407]; //1D array for cylinder.
float[] Horsepower = new float[407]; //1D array for Horsepower.
float[] Weight = new float[407]; //1D array for Weight.
float[] Acceleration = new float[407]; //1D array for Acceleration.
float[] carYear = new float[407]; //1D array for carYear.
float[] Origin = new float[407]; //1D array for Origin. (please convert to int then stick in it, and change String[] to int[].)
//Normalized values to plot.
float[] MPG_norm = new float[407]; //1D array for MPG.
float[] Cylinder_norm = new float[407]; //1D array for cylinder.
float[] Horsepower_norm = new float[407]; //1D array for Horsepower.
float[] Weight_norm = new float[407]; //1D array for Weight.
float[] Acceleration_norm = new float[407]; //1D array for Acceleration.
float[] carYear_norm = new float[407]; //1D array for carYear.
float[] Origin_norm = new float[407]; //1D array for Origin.
//Min and Max values for each of the attributes.
float minMPG = 0;
float maxMPG = 0;
float minCylinder = 0;
float maxCylinder = 0;
float minHorsepower = 0;
float maxHorsepower = 0;
float minWeight = 0;
float maxWeight = 0;
float minAcceleration = 0;
float maxAcceleration = 0;
float mincarYear = 0;
float maxcarYear = 0;
float minOrigin = 0;
float maxOrigin = 0;
void setup()
{
size(900, 900);
f = loadFont("TimesNewRomanPSMT-16.vlw");
grid = new Cell[cols][rows];
for (int i = 0; i < cols; i++)
{
for (int j = 0; j < rows; j++)
{
grid[i][j] = new Cell(i*20, j*20, 100, 80);
}
}
importData();
}
void importData()
{
String[] data = loadStrings("a1-cars.csv");
String[] temp = new String[500];
int index = 0;
//Will load the data files into the 2D array.
for (int i = 1; i < data.length; i++)
{
temp = split(data[i],",");
for (int j = 0; j < 10; j++)
{
carData[i][j] = temp[j];
//print(carData[i][j] + " "); //Just to see if it works.
}
//System.out.println(); //Just to make the formatting look nice.
}
//Will loop through the 2D array and then store the values of each individual attribute into it's respective array.
//The temporary variable origin will store a String, then the string would be converted into an int, to be able to store into
//the origin array (which is a int).
String originTemp = "";
for (int i = 1; i < data.length; i++)
{
MPG[i] = float(carData[i][2]); //Read the values from 2D array, then convert the input to an int.
MPG[i-1] = MPG[i]; //Shift all the values to index 0.
//print(MPG[i] + " "); //Just to see if it works.
Cylinder[i] = float(carData[i][3]); //Read the values from 2D array, then convert the input to an int.
Cylinder[i-1] = Cylinder[i]; //Shift all the values to index 0.
//print(Cylinder[i-1] + " ");
Horsepower[i] = float(carData[i][5]); //Read the values from 2D array, then convert the input to an int.
Horsepower[i-1] = Horsepower[i]; //Shift all the values to index 0.
//print(Horsepower[i] + " ");
Weight[i] = float(carData[i][6]); //Read the values from 2D array, then convert the input to an int.
Weight[i-1] = Weight[i]; //Shift all the values to index 0.
//print(Weight[i] + " ");
Acceleration[i] = float(carData[i][7]); //Read the values from 2D array, then convert the input to an int.
Acceleration[i-1] = Acceleration[i];
//print(Acceleration[i] + " ");
carYear[i] = float(carData[i][8]); //Read the values from 2D array, then convert the input to an int.
carYear[i-1] = carYear[i];
//print(carYear[i] + " ");
//After storing a String element into a temp String, each integer will represent an origin. 1 = American, 2 = European, 3 = Japanese.
originTemp = carData[i][9];
if (originTemp.equals("American"))
{
Origin[i] = 1; //Read the values from 2D array, then convert the input to an int.
//print(Origin[i] + " ");
}
else if (originTemp.equals("European"))
{
Origin[i] = 2; //Read the values from 2D array, then convert the input to an int.
//print(Origin[i] + " ");
}
else if (originTemp.equals("Japanese"))
{
Origin[i] = 3; //Read the values from 2D array, then convert the input to an int.
//print(Origin[i] + " ");
}
Origin[i-1] = Origin[i];
originTemp = ""; //Reset the temp variable origin.
//System.out.println(); //Just to make the formatting look nice.
}
//Find the min and max values for each attribute.
minMPG = min(MPG);
//print("min MPG: " + minMPG + " "); //Is it 9?
maxMPG = max(MPG);
//print("max MPG: " + maxMPG + " ");
minCylinder = min(Cylinder);
//print("min Cyl: " + minCylinder + " "); //Should be 3. But min() keeps finding 0.