I need count the number of rows and columns
in
Programming Questions
•
4 months ago
Hello! I need a code to count the number of rows and columns that I have in a. THE number of rows in the account but the number of columns does not ... How I can fix it?
my code is:
color[] minard = {#666666, #607F9C, #E9CCAE, #FFFFF3, #D01312};
color[] palette = minard;
PFont labelFont;
Table datos;
int rowCount;
int var;
int [][] variables;
int d = 10;
float xmin, xmax, ymin, ymax;
void setup() {
size(1000, 600);
datos = new Table("datos.tsv");
rowCount = datos.getRowCount();
println("Numero de datos = " + rowCount);
var = datos.getColumnCount();
println("Numero de variables = " + var);
labelFont = loadFont("GillSans-Bold-18.vlw");
smooth();
}
void draw() {
background(palette[0]);
textFont(labelFont);
stroke(180);
fill(180);
// Calculo del máximo y mínimo del PCA para los ejes x e y
float xmin =datos.getFloat(0,14);
float xmax =datos.getFloat(0,14);
for(int f = 0;f < rowCount; f++) {
float mat =datos.getFloat(f,14);
if (mat < xmin) {
xmin=mat;
}
if (mat > xmax){
xmax=mat;
}
}
float ymin =datos.getFloat(0,15);
float ymax =datos.getFloat(0,15);
for(int j = 0;j < rowCount; j++) {
float mat =datos.getFloat(j,15);
if (mat < ymin) {
ymin=mat;
}
if (mat > ymax){
ymax=mat;
}
}
// Line title PCA
textAlign(CENTER);
text("PCA",425,30);
// Line and labels for X axis
textAlign(CENTER);
line(200, 400, 650, 400);
text (xmin, 200, 420);
text (xmax, 650,420);
text("1ra Componente", 420, 445);
text("x min",200,450);
text("x max",650,450);
// Line and labels for Y axis
textAlign(RIGHT);
line(200, 50, 200, 400);
text (ymax, 195, 50);
text (ymin, 195,400);
text("2da Componente", 180, 250);
text("y max",100,50);
text("y min",100,400);
// Gets data, draws dots
for (int row = 0; row < rowCount; row++) {
// Para visualizar las variables
String dato = datos.getString(row, 0);
// score1
float score1 = datos.getFloat(row, 14);
float x = map(score1, xmin+(xmin/10), xmax+(xmax/10), 200, 650);
// score2
float score2 = datos.getFloat(row, 15);
float y = map(score2, ymin+(ymin/10), ymax+(ymax/10), 400, 50);
noStroke();
fill(#FFBA00, 180);
ellipse(x, y, d, d);
textAlign(LEFT);
fill(180);
if(dist(x, y, mouseX, mouseY) < (d/2+1)) {
text(dato, x, y - 10);
}
}
}
and the table is:
class Table {
int rowCount;
int var;
String[][] data;
String[][] datas;
Table(String filename) {
String[] rows = loadStrings(filename);
String[] bar = loadStrings(filename);
data = new String[rows.length][bar.length];
for (int i = 0; i < rows.length; i++) {
if (trim(rows[i]).length() == 0) {
continue; // skip empty rows
}
if (rows[i].startsWith("#")) {
continue; // skip comment lines
}
// split the row on the tabs
String[] pieces = split(rows[i], TAB);
// copy to the table array
data[rowCount] = pieces;
rowCount++;
// this could be done in one fell swoop via:
//data[rowCount++] = split(rows[i], TAB);
}
// resize the 'data' array as necessary
data = (String[][]) subset(data, 0, rowCount);
// Contar variables
for (int j = 0; j < bar.length; j++) {
var++;
}
}// fin del table
int getRowCount() {
return rowCount;
}
int getColumnCount(){
return var;
}
// find a row by its name, returns -1 if no row found
int getRowIndex(String name) {
for (int i = 0; i < rowCount; i++) {
if (data[i][0].equals(name)) {
return i;
}
}
println("No row named '" + name + "' was found");
return -1;
}
String getRowName(int row) {
return getString(row, 0);
}
String getString(int rowIndex, int column) {
return data[rowIndex][column];
}
String getString(String rowName, int column) {
return getString(getRowIndex(rowName), column);
}
int getInt(String rowName, int column) {
return parseInt(getString(rowName, column));
}
int getInt(int rowIndex, int column) {
return parseInt(getString(rowIndex, column));
}
float getFloat(String rowName, int column) {
return parseFloat(getString(rowName, column));
}
float getFloat(int rowIndex, int column) {
return parseFloat(getString(rowIndex, column));
}
void setRowName(int row, String what) {
data[row][0] = what;
}
void setString(int rowIndex, int column, String what) {
data[rowIndex][column] = what;
}
void setString(String rowName, int column, String what) {
int rowIndex = getRowIndex(rowName);
data[rowIndex][column] = what;
}
void setInt(int rowIndex, int column, int what) {
data[rowIndex][column] = str(what);
}
void setInt(String rowName, int column, int what) {
int rowIndex = getRowIndex(rowName);
data[rowIndex][column] = str(what);
}
void setFloat(int rowIndex, int column, float what) {
data[rowIndex][column] = str(what);
}
void setFloat(String rowName, int column, float what) {
int rowIndex = getRowIndex(rowName);
data[rowIndex][column] = str(what);
}
}
1