MathWorks - Mobile View
  • Sign In to Your MathWorks AccountSe connecter
  • Access your MathWorks Account
    • Mon compte
    • Mon profil
    • Mes licences
    • Se déconnecter
  • Produits
  • Solutions
  • Le monde académique
  • Support
  • Communauté
  • Événements
  • Obtenir MATLAB
MathWorks
  • Produits
  • Solutions
  • Le monde académique
  • Support
  • Communauté
  • Événements
  • Obtenir MATLAB
  • Sign In to Your MathWorks AccountSe connecter
  • Access your MathWorks Account
    • Mon compte
    • Mon profil
    • Mes licences
    • Se déconnecter

Vidéos et webinars

  • MathWorks
  • Vidéos
  • Vidéos
  • Recherche
  • Vidéos
  • Recherche
  • Contacter un commercial
  • Version d'essai
  Register to watch video
  • Description
  • Full Transcript
  • Related Resources

Reading Excel Data into MATLAB with a GUI, Part 1

From the series: Reading Excel Data into MATLAB with a GUI

Doug Hull, MathWorks

(Originally posted on Doug's MATLAB Video Tutorials blog.)

It was pretty easy to read in the data with XLSREAD. Note that three minutes into the video above, I use a neat cell mode trick that many might not know about.

Recorded: 28 Sep 2007

Our question today comes from one of our MATLAB® users named Sarah, who is trying to read in an Excel® file and do some plotting of the data in that Excel file in MATLAB. Let's look at the file that she sent me.

We can see that there are a lot of different columns here of data and that, not including the header row, we go down and see there are 60 different values in here. And so we want to read that into MATLAB and get a graph out. That graph is going to be just of one column versus another.

So how would we do that in MATLAB? We can see the file that we wrote here to solve this problem. The first thing is I need to know the file name that we want to read in and that just happens to be shown right here. You can see this is probably part of a series of many files that she's going to be reading in and doing graphics on.

So to read this data in, we simply are going to say A is equal to xlsread and then the file name. That's going to allow MATLAB to read in this data. Let's select those two lines of code only, right click, and say Evaluate Selection. That's going to run those two pieces of code.

Now if we go to the workspace browser, what we're going to see is we have the file name defined and, of course, that data-- 59 rows, as expected, and then 89 columns from the 89 columns of data on the first sheet of that worksheet. We could have specified to read sheet 2 or 3, but the data we were interested in happened to be on the first, so we didn't have to specify. It was just the default.

Now that we have this A data, why don't we turn it into columns that are easier to work with? In this case, maybe we wanted to plot the x values, which would be just what was stored in the first column, which was basically counting from 1 to 60. And in y, we're going to read in, let's say, the 20th column and plot that.

So we can simply take this A matrix and say I want x to be—take A, all the rows, column 1, and make that x. Then we're going to do the same thing for y. We're just going to say, let y be equal to matrix A, all the rows-- that's what the column means-- comma 60, so the 60th column. And then we will plot this.

So let's select those commands and evaluate selection. And we see that we have this plot out there. So that's how simple it can be to bring in this data and plot it inside of MATLAB.

Now let's show a little bit more advanced trick here. Let me move my windows around so you can see two of them at once. And let's say that, instead of just plotting number 60, we might want plot 61. So I'll change that to 61 and hit F5 to save and run, and that's going to update my plot.

But let's say I want to look at a lot of these. What I can do is select that number, come up here to the cell mode, make sure it's enabled by going to Cell and Disable or Enable Cell Mode, and hit plus 1. It's going to increment that value 61 to 62 and re-evaluate everything in that cell, or in this case, the entire file. We hit that again and we'll see number 63, 64, and so on. So you could go through here and look at your data in a very quick manner doing that little trick.

OK. As always, if you have questions, send them to me and we'll see if we can't answer them in this forum. Thank you.

Related Products

  • MATLAB
Related Information
MATLAB Video Blog

Feedback

Featured Product

MATLAB

  • Request Trial
  • Get Pricing

Up Next:

Once this was done, it was time to turn that script into a function so that it could be reused easily.
5:05
Part 2
View full series (4 Videos)

Related Videos:

5:10
Reading Excel Data into MATLAB with a GUI, Part 4
13:48
Reading Excel Data into MATLAB with a GUI, Part 3
5:05
Reading Excel Data into MATLAB with a GUI, Part 2
6:42
Building a GUI to Read, Modify and Write an Excel File,...
6:24
Building a GUI to Read, Modify and Write an Excel File,...

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: .

Select web site

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

  • Contacter un commercial
  • Version d'essai

Découvrir les produits

  • MATLAB
  • Simulink
  • Version étudiante
  • Support Hardware
  • File Exchange

Essayer ou Acheter

  • Téléchargements
  • Version d'essai
  • Contacter un commercial
  • Tarifs et licences
  • Comment acheter

Se Former

  • Documentation
  • Tutoriels
  • Exemples
  • Vidéos et webinars
  • Formation

Obtenir de l'aide

  • Aide à l'installation
  • Forum MATLAB
  • Services de consulting
  • Gestion Licences
  • Contacter le support technique

La société

  • Offres d'emploi
  • Actualités
  • Social Mission
  • Contacter un commercial
  • La société

MathWorks

Accelerating the pace of engineering and science

MathWorks est le leader mondial des logiciels de calcul mathématique pour les ingénieurs et les scientifiques.

Découvrir…

  • Select a Web Site United States
  • Brevets
  • Marques déposées
  • Charte de confidentialité
  • Lutte anti-piratage
  • État des applications

© 1994-2021 The MathWorks, Inc.

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

Rejoignez la conversation

This website uses cookies to improve your user experience, personalize content and ads, and analyze website traffic.  By continuing to use this website, you consent to our use of cookies.  Please see our Privacy Policy to learn more about cookies and how to change your settings.