Stats

Popular Posts

Followers

Import data from Excel files into Mathematica

養花種魚數月亮賞星星 於 2008年3月27日星期四 上午10:42 發表
mathematica;教學;pdf mathematica 6教學 mathematica基本教學

If your dataset named test.dat with space delimited has the following contents (Iris dataset).

1 5.1 3.5 1.4 0.2 setosa
2 4.9 3.0 1.4 0.2 setosa
3 4.7 3.2 1.3 0.2 setosa
4 4.6 3.1 1.5 0.2 setosa
5 5.0 3.6 1.4 0.2 setosa
6 5.4 3.9 1.7 0.4 setosa
7 4.6 3.4 1.4 0.3 setosa
8 5.0 3.4 1.5 0.2 setosa
9 4.4 2.9 1.4 0.2 setosa
10 4.9 3.1 1.5 0.1 setosa

You can read this into Mathematica with only one command:

mydata = ReadList["~/iris.txt", {Number, Real, Real, Real, Real, String}] ;

Show the dataset

mydata // TableForm

Read the 2-3 column from the dataset.

iris1 = mydata[[1, Table[i, {i, 1, 50}], {2, 3}]]; iris2 = mydata[[1, Table[i, {i, 51, 100}], {2, 3}]]; iris3 = mydata[[1, Table[i, {i, 101, 150}], {2, 3}]];

Plot the Scatter Plot

Step 1.

Needs["Graphics`MultipleListPlot`"];

Step 2.

MultipleListPlot[{iris1, iris2, iris3}, SymbolShape -> Point, SymbolStyle -> {{PointSize[0.015], Blue}, {PointSize[0.015], Green}, {PointSize[0.015], Red}}, PlotLegend -> {"setosa", "versicolor", "virginica"}, LegendPosition -> {1.07, .3}, LegendSize -> {.3, .3}, PlotRange -> {{4, 8}, {2, 4.5}} ]


Tags: ,

讀者回應 ( 0 意見 )

發佈留言

Please leave your name and tell me what you thought about this site. Comments, suggestions and views are welcomed.

如果這篇文章對你有幫助,那請留個訊息給我~