Skip to content
MathWorks - Mobile View
  • Sign In to Your MathWorks AccountSign In to Your MathWorks Account
  • Access your MathWorks Account
    • My Account
    • My Community Profile
    • Link License
    • Sign Out
  • Products
  • Solutions
  • Academia
  • Support
  • Community
  • Events
  • Get MATLAB
MathWorks
  • Products
  • Solutions
  • Academia
  • Support
  • Community
  • Events
  • Get MATLAB
  • Sign In to Your MathWorks AccountSign In to Your MathWorks Account
  • Access your MathWorks Account
    • My Account
    • My Community Profile
    • Link License
    • Sign Out

Videos and Webinars

  • MathWorks
  • Videos
  • Videos Home
  • Search
  • Videos Home
  • Search
  • Contact sales
  • Trial software
3:22 Video length is 3:22.
  • Description
  • Full Transcript
  • Related Resources

How to Import Data from Spreadsheets and Text Files Without Coding

Learn how to import spreadsheet data using the Import Tool. Although this video walks through how to import Excel® data, MATLAB® supports a variety of other file types, including .CSV documents, .txt files, and .JSON files. This video provides a step-by-step walkthrough of how to find your files, select sections of your data or the entire spreadsheet, import it as either a table or a matrix, and generate code. 

Hello and welcome to another MATLAB tutorial. Today we’re going to talk about importing spreadsheet data using the import tool.

The import tool is really straightforward to use, you just go up to the home bar and press the import button here and it asks you to select a file. I have list of possible files to choose from in this folder, some are CSV, excel docs, txt files.

MATLAB supports a wide variety of file types as you can see in the documentation, but today we’re focusing on spreadsheets and text files. That said you can import images, videos, etc outside of the import tool. Additionally, if you have a file such as a JSON, you can use the file read function and import it as text.

Yeah so when you open the import tool, you get a window to select file, select the file you need. Here we’re going to choose this excel file. You can have more than one file open at once, you just tap import data again and you get the same options and then I’m going to select this txt file. And boom we have two documents we can toggle between. In a similar vein, if you have more than one sheet in your excel doc it imports those as well.

When importing txt files, the import tool is relatively smart and can figure out the delimiter in the file. As you can see with this file.

But if it gets it wrong as it did with this baa delimited text file, bsv if you will, you can go up here to the column delimiters and just select the right one. It gives you suggested delimiters with a button here to enter a custom delimiter if what you need is not mentioned. When it comes to fixed width delaminated text files it gets a little trickier. You have to click the fixed width button and then it reformats, and you can take these lines here and move them create the columns.

The import tool can also recognize the variable type of the particular columns. Including datetime and identifying constant characters such as dollar signs or percentages as you can see here.

If you want, you can import the entirety of the spreadsheet as table but let’s say you don’t. You can select and deselect columns by ctrl-clicking or highlight the sections you want or go up here to the range box and select a range of values to import. The values don’t have to be continuous, you can pretty much completely pick and choose so long as the columns are consistent.  

You also don’t have to import as a table, you can import as matrix for example. However, this selection includes values that are not numbers. Brightly highlighted in yellow here. You can control how these un-importable values are imported up here, you can replace them as NaNs or Zeros, or just exclude those rows and/or columns all together. If you don’t specify a rule here and you have an un-importable value, the import tool won’t let you import.

So now the data is selected, you have two options, you can either press the import button and import the data into the workspace like this:

See really simple.

Or you can select the drop down and generate code. You have a couple of different options, you can generate it as a function, script, or live script. Depending on what you need.

This is helpful if you want to automate the importing of one or many files as you can program it to loop though different files by changing the file location and output name on each loop.

If you’re curious about learning more about the code for importing data, I’d recommend checking out our video on the topic.

Thanks for watching, and happy coding. 

Related Products

  • MATLAB

3 Ways to Speed Up Model Predictive Controllers

Read white paper

A Practical Guide to Deep Learning: From Data to Deployment

Read ebook

Bridging Wireless Communications Design and Testing with MATLAB

Read white paper

Deep Learning and Traditional Machine Learning: Choosing the Right Approach

Read ebook

Hardware-in-the-Loop Testing for Power Electronics Control Design

Read white paper

Predictive Maintenance with MATLAB

Read ebook

Electric Vehicle Modeling and Simulation - Architecture to Deployment : Webinar Series

Register for Free

How much do you know about power conversion control?

Start quiz

Feedback

Featured Product

MATLAB

  • Request Trial
  • Get Pricing

Up Next:

6:21
Import Tool Enhancements for Text Files

Related Videos:

2:33
How to Import Data from Files Programmatically
2:09
How to Store a Series of Vectors from a for Loop
28:30
A Novel Method to Build Real-World Drive Cycles from...
33:26
Developing Forecast Models from Time-Series Data in MATLAB...

View more related videos

MathWorks - Domain Selector

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

  • Switzerland (English)
  • Switzerland (Deutsch)
  • Switzerland (Français)
  • 中国 (简体中文)
  • 中国 (English)

You can also select a web site from the following list:

How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
    • 简体中文Chinese
    • English
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

Contact your local office

  • Contact sales
  • Trial software

MathWorks

Accelerating the pace of engineering and science

MathWorks is the leading developer of mathematical computing software for engineers and scientists.

Discover…

Explore Products

  • MATLAB
  • Simulink
  • Student Software
  • Hardware Support
  • File Exchange

Try or Buy

  • Downloads
  • Trial Software
  • Contact Sales
  • Pricing and Licensing
  • How to Buy

Learn to Use

  • Documentation
  • Tutorials
  • Examples
  • Videos and Webinars
  • Training

Get Support

  • Installation Help
  • MATLAB Answers
  • Consulting
  • License Center
  • Contact Support

About MathWorks

  • Careers
  • Newsroom
  • Social Mission
  • Customer Stories
  • About MathWorks
  • Select a Web Site United States
  • Trust Center
  • Trademarks
  • Privacy Policy
  • Preventing Piracy
  • Application Status

© 1994-2022 The MathWorks, Inc.

  • Facebook
  • Twitter
  • Instagram
  • YouTube
  • LinkedIn
  • RSS

Join the conversation