Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

139
Views
Cómo iterar sobre las filas de una tabla con p5js usando table.setNum()
function saveAsCSV() { let simulationOutput = new p5.Table(); let newRow = simulationOutput.addRow(); simulationOutput.addColumn("Total Population"); simulationOutput.addColumn("Human Population"); simulationOutput.addColumn("Predator Population"); simulationOutput.addColumn("Prey Population"); simulationOutput.addColumn("Food Population"); for(var i = 1; i<totalDynamic.length; i++){ simulationOutput.addRow().setNum("Total Population", int(totalDynamic[i])); } for(let j = 1; j<predDynamic.length; j++){ simulationOutput.setNum(j,1, int(predDynamic[j])); j++; } save(simulationOutput, month()+"/"+day()+"_T:"+hour()+":"+minute()+":"+second()+"_Simulation_Output.csv"); }

Estoy buscando guardar los resultados de una simulación en un archivo .csv, pero parece que no puedo iterar sobre las filas de la tabla usando el ciclo for. estoy usando p5.js

 for(let j = 1; j<predDynamic.length; j++){ simulationOutput.setNum(j,1, int(predDynamic[j])); j++;}

Obtuve el siguiente error:

 Uncaught TypeError: Cannot read properties of undefined (reading 'setNum') at o.default.Table.setNum (p5.min.js:3:593463) at o.default.Element.saveAsCSV (predator_prey.js:255:22) at o.default.Element.<anonymous> (p5.min.js:3:429692)

El problema es iterar usando j, pero no puedo ver cómo esto devuelve indefinido.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Recibe este error porque totalDynamic.length < predDynamic.length

Se agrega una fila para cada elemento en totalDynamic y no en predDynamic . Pero cuando hay más elementos en predDynamic que en totalDynamic , p5.Table() no reconoce las filas porque aún no se han inicializado. Solución posible:

 for(let j = 1; j<predDynamic.length; j++){ if(simulationOutput.rows.length <= j) simulationOutput.addRow(); simulationOutput.setNum(j,1, int(predDynamic[j])); j++; }
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!