Gary Palmer

84 Reputation

11 Badges

16 years, 255 days




Mac w OS X, 10.4.6, 3.06 GHz Intel Duo with 4GB RAM, Maple14 Student

MaplePrimes Activity

These are answers submitted by Gary Palmer

It's hard to answer your question without knowing more about the structure of the data in the csv file and what kind of errors you are getting. Basically you just have a text file in which data elements are separated by commas. Here is an example that reads lines and prints a point for each line. In your case, you will be dealing with integers or floating point numbers, so you will probably want to use something like readdata(filename, [float, float, float]). The readdata procedure assumes that the elements in each line of the csv file are separated by spaces, like this in a file named "datawspaces.csv":

1.5 .7 33.6
2.2 3.7 1.5
8.7 5.0 3.2
Then you could run something like the following:

myPath := "/Users/<home>/datafolder/": # your path to the CSV file

theCSVfile := cat(myPath, "datawspaces.csv");

data := readdata(theCSVfile, [float, float, float]); # turns those text numbers into real (floating point) numbers

data[1,1]+data[2,1]+data[3,1]; # prints 12.4

pts := [seq(point(data[i], symbol = circle, symbolsize = 25), i = 1..3)];
display(pts, labels = [x, y, z]); # displays three points

If the data elements in the file are actually separated by commas, then you would have to look at what readdata was yielding. You might be getting the data in a long list, or you might be getting partial data. Depending on what you find, you might want to use fscanf to read the data instead of readdata. It's described in the advanced users manual and listed in the index. Or you might want to preprocess the file to make it readable with readdata. If you have to split the data on the commas, then StringTools[RegSplit] might be useful.



Mac w OS X, 10.4.6, 3.06 GHz Intel Duo with 4GB RAM, Maple14 Student

Thanks. As you suggest, it looks involved, but there are things in the thread and your script that I can use. I think I will abandon the general idea of putting maple in the pipeline and use hard files for data transfers to and from maple.


Mac w OS X, 10.4.6, 3.06 GHz Intel Duo with 4GB RAM, Maple14 Student

Page 1 of 1