I am faced with the challenge of extracting values from one array based on indices from another array. I have successfully loaded two text files using loadStrings and stored the data in two separate arrays. The lengths of the two text files are different - the first file includes three values per line: a line number, an x coordinate, and a y coordinate. The second file contains the line numbers from the first file for which I need to extract data. With only two months of coding experience, I find this task daunting and it has left me stuck! Below is the code I have managed to write so far:
let data1;
let data2;
let parsedData1;
let parsedData2;
let combinedData;
function preload() {
data1 = loadStrings('assets/data1.txt'); // load the data1 file
data2 = loadStrings('assets/data2.txt'); // load the data2 file
// console.log(data1);
// console.log(data2);
}
function setup() {
createCanvas(600, 400);
}
function draw() {
noLoop();
background(0);
readData1()
readData2()
}
function readData1() {
parsedData1 = new Array(data1.length); // create an array for the parsed data
for (let i = 0; i < data1.length; i++) {
let parsedData1 = splitTokens(data1[i]);
// console.log(data1);
}
}
function readData2() {
let combinedData = concat(parsedData1, data2);
// console.log(combinedData);
}
The text files I have loaded contain the following information:
text1:
1 200 50
2 100 25
3 200 63
4 123 456
5 124 200
6 700 500
7 600 500
8 200 121
9 300 100
text2:
3
5
8
The desired result I am aiming for is:
3 150 100
5 124 200
8 200 121
I have been advised that loops can help achieve the desired result, but I am still working on figuring out how!