Ken & Mike on 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

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>

If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).


Ken & Mike work on the MATLAB Desktop team.
  • DP: Hi i have a problem with ezplot3, i want to plot more than i curve in the same graph but hold on command...
  • Ken: Hi Arsalan, Unfortunately there is no way to get the new Editor API in older versions of MATLAB. -Ken
  • Arsalan: Hi, I am very excited about the MATLAB API for editor because right now i am working on a project and i need...
  • Johannes: Since I started using matlab-emacs some days ago I never experienced Emacslink. But I experienced some...
  • Francisco J. Beron-Vera: Hi all, I have recently learned about ViEmu (http://www.vimemu.c om) which, for Vi/Vim...
  • OysterEngineer: When I first learned of the Publish feature in MatLab, I thought it might be useful to help to...
  • Ken: Hi Herve, I’m not quite sure what you mean by “stand-alone&# 8221; mode? -Ken
  • Herve: I wonder when the publish fonction will be supported in standalone mode.
  • Mike: Ravi, What you described should work as far I understand it. Please follow up with technical support. With a...
  • Mike: @Daniel, Thanks for that note.

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