How to | Import and Export File Elements

Sometimes you may want to work with a specific part of a file instead of all of it. When bringing a file into Mathematica, you can elect to import just individual parts of the file, which are called elements. Mathematica's ability to import and export elements of files gives you greater control over the information being exchanged while simultaneously saving time and memory.

Begin by importing an image from the Mathematica documentation directory ExampleData:

Click for copyable input

Use as the second argument in Import to view the elements of the image that are available for import:

Click for copyable input

Get the pixel size of the image:

Click for copyable input

Import the complete of the image and set it to the variable . Since is large and you do not need to view all of it, the output is suppressed here with a semicolon:

Click for copyable input

You can now analyze the image data, for example by using ListPlot3D:

Click for copyable input

After importing, you can then export elements to control exactly what is exported. This gives you a great deal of extensibility when working with data in different files and formats.

Import the first sheet of data from the spreadsheets and from the Mathematica documentation directory ExampleData:

Click for copyable input
Click for copyable input

Export these to separate sheets in a single spreadsheet file:

Click for copyable input

The specific Import and Export elements that can be used depend on the file formats you are working with. For more information, see the documentation pages for the formats. There is also some additional information in How to: Import and Export.

New to Mathematica? Find your learning path »
Have a question? Ask support »