2
$\begingroup$

I have an excel spreadsheet that I would like to plot in a 3D graph using mathematica. The X and Y values are the location of the cell, and the Z value is the number of the scale.

How can I import this into mathematica for plotting purposes?

Here is what my data looks like. enter image description here

$\endgroup$
  • 1
    $\begingroup$ You can factor your Q into two parts: (1) data = Import["myFile.xls"] (if the file contains only a single worksheet, otherwise take parts). (2) Then you can transform this data to Graphics3D in a variety of ways. $\endgroup$ – alancalvitti Jan 25 '13 at 18:46
  • $\begingroup$ @alancalvitti that worked... if you add it as an answer I will select it. $\endgroup$ – Sponge Bob Jan 25 '13 at 19:07
4
$\begingroup$
Flatten[MapIndexed[{Sequence @@ #2, #1} &, 
                Import["ExampleData/elements.xls"] [[1]], {2}], 1] // TableForm

Requested explanation:

Import["ExampleData/elements.xls"][[1]]

Gets the first sheet in the file

MapIndexed[{Sequence @@ #2, #1} &, ...... , {2}]

Generates tuples of the form {posx, posy, cellValue}

Flatten[........, 1]

Gets rid of extra nesting levels on the resulting list

// TableForm

Formats the output you see below

enter image description here

$\endgroup$
  • $\begingroup$ This works great. Thank you. Do you think you could explain what it is doing, please? $\endgroup$ – Sponge Bob Jan 25 '13 at 19:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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