Skip to Main Content Skip to Search
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Inside the MATLAB Desktop

October 15th, 2007

Drag and Drop Data Import

I’ll occasionally contribute to this blog to focus on the data-related tools in the MATLAB Desktop. We provide a lot of tools to help you import, organize, visualize, and explore your data in MATLAB . I’m going to help you learn about them and give you hints for new ways to use them. Remember, menus and dialogs aren’t the only way to get things done! Drag-and-drop and right-click context menus can smooth your workflow a lot.

Let’s start by learning how to drag-and-drop data into MATLAB. Suppose that you’ve got an interesting data file on your computer’s desktop. To play along at home, drag the following picture from your web browser onto your desktop. That should save a PNG to your desktop.

Team Photo for DnD Demo

What’s a good way to get that image data into MATLAB? You could go to the Command Window and use IMREAD, but let’s think “drag-and-drop” and “GUIs” for a few minutes.

The Workspace window in the MATLAB Desktop is where your MATLAB data lives. So, it interprets dropping a file onto it as “please turn this file into MATLAB data.” Try it! Click on the Workspace tab to bring it to the foreground, in front of any other windows in the MATLAB Desktop.

Empty Workspace

Now, select the JPEG file that you just created and drop it onto the Workspace

Dropping file onto Workpsace

The Workspace knows that you want to create some data from that file, so it opens the MATLAB Import Wizard, the point-and-click UI for importing common file formats.

Import Wizard

Click the Import Wizard’s Finish button, and you’re done. A variable containing your data has appeared in the Workspace. (Since the name of the variable is based on the file name, your variable name may differ from the screenshot.)

WorkspaceVar.png

Let’s double-check. Select that new variable in the Workspace, and right-click. You’ll see a menu with a bunch of options, including some graphics-related options near the bottom. Select the “imagesc” option.

Workspace selecting Imagesc

This will create a scaled image of that data in a Figure window. Sure enough, it’s the image that you dropped onto the Workspace.

Finished Figure

The image is blown up a lot from the original, so it’s pretty pixelated.

I hope that this courages you to start trying drag-and-drop more when using the MATLAB Desktop. If something doesn’t work the way you expect, be sure to tell us!

In future posts I’ll go into more detail about the Import Wizard and the Workspace, and then start moving into other data management tools.

3 Responses to “Drag and Drop Data Import”

  1. Neha replied on :

    Hi,

    I need to import data from about 25,000 files and parse data in them to create an xml. Is there any toolbox that you can suggest?

    Thanks!

  2. Ken replied on :

    Hey Neha,

    Check out the xmlread function - you won’t need any special toolboxes to use it. This function will return a Document Object Model (DOM) node which you can manipulate as needed.

    -Ken

  3. sri replied on :

    thanks for providing information

Leave a Reply


Inside the MATLAB Desktop is written by the MATLAB Interface teams.

Team picture
  • Ken: Hi Bjoern, We’re currently working hard to make it easier to add support for additional languages in the...
  • Bjoern: Hi, As all the other matlab users out there who have to work with different programming languages - I would...
  • Mike: bswang, Depending on where your data is coming from, it may not be available from your standalone program (e.g....
  • Ken: Hi Han, Thats an interesting idea, one also present in Xcode via the #pragma mark token. There’s a school...
  • Han Geerligs: Hello Ken, how about introducing the “region” concept as used in the Visual Studio...
  • bswang: I use a uitable in guide. The uitable works well on the matlab environment. But when i build the mytest.m...
  • Jennifer French: Hi Stephen, Thanks for posting about dataset. Its great to hear about techniques that work well for...
  • Jennifer French: Hi Quan, Thanks for sharing those techniques for working with excel! They sound quite useful and...
  • Ken: @Steven: Thanks for the great feedback! We’d love to hear more about how you use the dataset function when...
  • Ken: @Quan: xlsread is a great function! Also, I like your cut and paste technique.

These postings are the author's and don't necessarily represent the opinions of The MathWorks.

Related Topics