3
$\begingroup$

After reading the documentation, this was my first attempt:

import ["C:\\...\\pfc.dat", "Table"]
ListPlot3D[Table];

I get "arrayerr::Table must be a valid array or list of valid arrays".

The data is formatted like x,y,z e.g. 0,1,0.9

I realize this is simple but I don't understand why it is failing.

$\endgroup$
4
  • $\begingroup$ Have you tried ListPointPlot3D? $\endgroup$
    – Feyre
    Commented Aug 30, 2016 at 17:09
  • 1
    $\begingroup$ Table is a function, so you're supplying the ListPlot3D with a wrong argument. $\endgroup$
    – iav
    Commented Aug 30, 2016 at 17:34
  • $\begingroup$ Syntax you used makes no sense, type Import and press F1, examples there should clarify that. $\endgroup$
    – Kuba
    Commented Aug 30, 2016 at 17:38
  • 1
    $\begingroup$ mathematica is Case Sensative, Import not import. Your data looks to be comma separated so read as data = Import[file,"CSV"] , then ListPlot3D[data] $\endgroup$
    – george2079
    Commented Aug 30, 2016 at 19:20

2 Answers 2

2
$\begingroup$

It looks simply like a syntax error. First of all, in MMA all commands are upper case, so you should do

data=Import["C:\\...\\pfc.dat","Table"]

Note a lack of space between Import and ["C:\\...\\pfc.dat","Table"].

Second, you want to plot a set of points, so instead using ListPlot3D you should use ListPointPlot3D.

Finally, you used Table as an argument of the plotting function, but as emphasized above, it is a built-in command. You should type

ListPointPlot3D[data]

possibly with any options you want - see @cyrille.piatecki's answer for an example.

$\endgroup$
0
$\begingroup$

As you are clearly a beginner I will decompose the process.

I suppose your file look like this one

 457.81 ,208.16 ,68.02
 46.71  ,8.69   ,2.99
 1198.97    ,195.99 ,3.99
 30.94  ,21.78  ,5.94
 4.43   ,6.64   ,4.95
-54.04  ,7.3    ,7.72
 127.70 ,42.76  ,6.22
-695.26 ,138.14 ,35
-226.36 ,4.98   ,8.33

you will see that the end of line is not specifically marked so one must provide to Mathematica the way to understand it.

Whichever be placed your file, you can load it with

l = ToString[Import["C:\\mypath\\data.txt"]]

This command read the file and transforms it in a string then we give a name to this string.

Now we want a string that looks like a List

l1 = StringSplit[l]

Unfortunately, this leads to the apparition of a not desired patern (, ,) To eliminate it we replace it

l2 = StringReplace[l1, "," -> " "]

Then we want to reconstruct a table

l3 = Partition[l2, 3]

To finish we need to comme back to an expression because we want to plot it

l4 = ToExpression[l3]

You can observe that it is a matrix of 3 columns so one can plot it

ListPointPlot3D[l4, 
PlotStyle -> {Directive[GrayLevel[0], Opacity[0.406]], 
PointSize[0.05]}, Filling -> Bottom, ColorFunction -> "Rainbow"]

Hope this fulfills your hopes.

$\endgroup$
2
  • 2
    $\begingroup$ Using simply Import["path","Table"] is sufficient - it imports exemplary data set without any problems. $\endgroup$
    – corey979
    Commented Aug 30, 2016 at 20:47
  • $\begingroup$ wonderful, thank you $\endgroup$
    – kyle moats
    Commented Aug 30, 2016 at 21:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.