How to load a table from a text file and apply algorithm

Hi, I'm new to programming in general and was wondering if anyone knew how to load a table from a text file. I want to do this so I can apply the nearest neighbour algorithm. I'm finding this extremely difficult and there aren't many helpful sources to help.

Thanks, If anyone would be able to guide me i'd be very grateful,

Tagged:

Answers

  • Did you look at reference | loadTable()?

    Read the examples for Table (reference as well) to learn how to access cells in the table.

    Eg you might want to for loop over the table

    also there is a tutorial on data

    Please read this

    Post your entire code and tell us where you are stuck (line Numbers)

    Post the first ten lines of your txt file please

  • edited April 2016

    If you have some odd table design in the text file you can:
    https://processing.org/reference/loadStrings_.html

    then use
    https://processing.org/reference/split_.html
    to get the data. Or, if you know specific table entries start with certain char you can use
    https://processing.org/reference/String_indexOf_.html
    to reconstruct the table.


    The first method is good for text file that looks like:

    words and stuff;365;2015;8;23;Friday;Monday
    more words;321;2221;4;22;Wednesday;Saturday
    



    The second method is good for something like:

    ~row1, entry1 }entry2 spaces don't matter if not split by spaces >entry3 ~row2, entry1 }row2, entry2 >row2, entry3



    loadTable() loads text files that look like:

    header1,header2,header3
    entry1,entry2,entry3
    row2entry1,row2entry2,row2entry3
    

    I hope that clears that up for you.

Sign In or Register to comment.