{"id":119,"date":"2007-10-15T11:32:53","date_gmt":"2007-10-15T16:32:53","guid":{"rendered":"https:\/\/blogs.mathworks.com\/desktop\/2007\/10\/15\/drag-and-drop-data-import\/"},"modified":"2007-10-22T12:09:03","modified_gmt":"2007-10-22T17:09:03","slug":"drag-and-drop-data-import","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/community\/2007\/10\/15\/drag-and-drop-data-import\/","title":{"rendered":"Drag and Drop Data Import"},"content":{"rendered":"<p class=\"MsoNormal\"><span style=\"font-family: Helvetica\">I&#8217;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&#8217;m going to help you learn about them and give you hints for new ways to use them.  Remember, menus and dialogs aren&#8217;t the only way to get things done!  Drag-and-drop and right-click context menus can smooth your workflow a lot.<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Helvetica\">Let&#8217;s start by learning how to drag-and-drop data into MATLAB.  Suppose that you&#8217;ve got an interesting data file on your computer&#8217;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.<br \/>\n<\/span><\/p>\n<p class=\"MsoNormal\"><img decoding=\"async\" id=\"image112\" alt=\"Team Photo for DnD Demo\" src=\"https:\/\/blogs.mathworks.com\/images\/desktop\/team_tiny-2.jpg\" \/><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Helvetica\">What&#8217;s a good way to get that image data into MATLAB?  You <em>could<\/em> go to the Command Window and use IMREAD, but let&#8217;s think &#8220;drag-and-drop&#8221; and &#8220;GUIs&#8221; for a few minutes.<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Helvetica\">The Workspace window in the MATLAB Desktop is where your MATLAB data lives.  So, it interprets dropping a file onto it as &#8220;please turn this file into MATLAB data.&#8221;  Try it!  Click on the Workspace tab to bring it to the foreground, in front of any other windows in the MATLAB Desktop.<br \/>\n<\/span><\/p>\n<p class=\"MsoNormal\"><img decoding=\"async\" id=\"image113\" alt=\"Empty Workspace\" src=\"https:\/\/blogs.mathworks.com\/images\/desktop\/EmptyWorkspace.png\" \/><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Helvetica\">Now, select the JPEG file that you just created and drop it onto the Workspace<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Helvetica\"><img decoding=\"async\" id=\"image114\" alt=\"Dropping file onto Workpsace\" src=\"https:\/\/blogs.mathworks.com\/images\/desktop\/DroppingFile.png\" \/><\/span><\/p>\n<p>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.<\/p>\n<p class=\"MsoNormal\"><img decoding=\"async\" id=\"image120\" alt=\"Import Wizard\" src=\"https:\/\/blogs.mathworks.com\/images\/desktop\/Untitled-3.png\" \/><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Helvetica\">Click the Import Wizard&#8217;s Finish button, and you&#8217;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.)<\/span><\/p>\n<p class=\"MsoNormal\"><img decoding=\"async\" id=\"image116\" alt=\"WorkspaceVar.png\" src=\"https:\/\/blogs.mathworks.com\/images\/desktop\/WorkspaceVar.png\" \/><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Helvetica\">Let&#8217;s double-check.  Select that new variable in the Workspace, and right-click.  You&#8217;ll see a menu with a bunch of options, including some graphics-related options near the bottom. Select the &#8220;imagesc&#8221; option.<\/span><\/p>\n<p class=\"MsoNormal\"><img decoding=\"async\" id=\"image117\" alt=\"Workspace selecting Imagesc\" src=\"https:\/\/blogs.mathworks.com\/images\/desktop\/WorkspaceImagesc.png\" \/><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Helvetica\">This will create a scaled image of that data in a Figure window.  Sure enough, it&#8217;s the image that you dropped onto the Workspace.<span \/><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Helvetica\"><img decoding=\"async\" alt=\"Finished Figure\" id=\"image121\" src=\"https:\/\/blogs.mathworks.com\/images\/desktop\/Untitled-4.png\" \/><br \/>\n<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Helvetica\">The image is blown up a lot from the original, so it&#8217;s pretty pixelated.<\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Helvetica\">I hope that this courages you to start trying drag-and-drop more when using the MATLAB Desktop.  If something doesn&#8217;t work the way you expect, be sure to tell us!<span \/><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Helvetica\" \/><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Helvetica\">In future posts I&#8217;ll go into more detail about the Import Wizard and the Workspace, and then start moving into other data management tools.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;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&#8230; <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/community\/2007\/10\/15\/drag-and-drop-data-import\/\">read more >><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[12],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/posts\/119"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/comments?post=119"}],"version-history":[{"count":0,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/posts\/119\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/media?parent=119"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/categories?post=119"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/community\/wp-json\/wp\/v2\/tags?post=119"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}