Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

share|improve this question
1  
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. –  alancalvitti Jan 25 '13 at 18:46
    
@alancalvitti that worked... if you add it as an answer I will select it. –  Sponge Bob Jan 25 '13 at 19:07
    
@Thanks - please go ahead and accept Belisarius' answer which is more detailed. –  alancalvitti Jan 25 '13 at 19:20

1 Answer 1

up vote 4 down vote accepted
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

share|improve this answer
    
This works great. Thank you. Do you think you could explain what it is doing, please? –  Sponge Bob Jan 25 '13 at 19:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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