{"id":237,"date":"2010-06-25T13:29:27","date_gmt":"2010-06-25T13:29:27","guid":{"rendered":"https:\/\/blogs.mathworks.com\/loren\/2010\/06\/25\/what-data-is-available\/"},"modified":"2018-01-08T15:16:04","modified_gmt":"2018-01-08T20:16:04","slug":"what-data-is-available","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/loren\/2010\/06\/25\/what-data-is-available\/","title":{"rendered":"What Data Is Available?"},"content":{"rendered":"<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n   <introduction>\r\n      <p>Yes, I know, data <b>are<\/b>, but the title just sounded terrible that way.\r\n      <\/p>\r\n      <p>Ever wonder what data you have stored in some files, particularly MATLAB MAT-files?  Sometimes I'd like to know what's there\r\n         without making the commitment to load the data.  Fortunately, there's a good way to accomplish this in MATLAB programmatically,\r\n         and another good way when viewing the Current Folder.  I will show you the programmatic way.\r\n      <\/p>\r\n   <\/introduction>\r\n   <h3>Contents<\/h3>\r\n   <div>\r\n      <ul>\r\n         <li><a href=\"#1\">Files to Look at<\/a><\/li>\r\n         <li><a href=\"#2\">Peek Inside<\/a><\/li>\r\n         <li><a href=\"#5\">Loading Some Data<\/a><\/li>\r\n         <li><a href=\"#8\">Do You Load Data Selectively?<\/a><\/li>\r\n      <\/ul>\r\n   <\/div>\r\n   <h3>Files to Look at<a name=\"1\"><\/a><\/h3>\r\n   <p>Let's first identify some files to look at.  I happen to know that we have some data for demos stored on the MATLAB <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2010a\/techdoc\/ref\/path.html\"><tt>path<\/tt><\/a>.  These include the files <tt>durer.mat<\/tt>, <tt>seamount.mat<\/tt>, and <tt>clown.mat<\/tt>.\r\n   <\/p>\r\n   <h3>Peek Inside<a name=\"2\"><\/a><\/h3>\r\n   <p>Let's take a peek inside the seamount data.  I can do this using a variant of the <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2010a\/techdoc\/ref\/whos.html\"><tt>whos<\/tt><\/a> function.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">whos <span style=\"color: #A020F0\">-file<\/span> <span style=\"color: #A020F0\">seamount.mat<\/span><\/pre><pre style=\"font-style:oblique\">  Name           Size             Bytes  Class     Attributes\r\n\r\n  caption        1x229              458  char                \r\n  x            294x1               2352  double              \r\n  y            294x1               2352  double              \r\n  z            294x1               2352  double              \r\n\r\n<\/pre><p>And what's lurking inside <tt>topo.mat<\/tt>?\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">whos <span style=\"color: #A020F0\">-file<\/span> <span style=\"color: #A020F0\">topo<\/span><\/pre><pre style=\"font-style:oblique\">  Name              Size              Bytes  Class     Attributes\r\n\r\n  topo            180x360            518400  double              \r\n  topolegend        1x3                  24  double              \r\n  topomap1         64x3                1536  double              \r\n  topomap2        128x3                3072  double              \r\n\r\n<\/pre><p>Notice in this case, there are 4 variables, including 2 starting with the name \"topomap\".  Suppose I want to find all the\r\n      variables with names beginning with \"topom\".  I can use the wildcard character \"*\".\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">whos <span style=\"color: #A020F0\">topom*<\/span> <span style=\"color: #A020F0\">-file<\/span> <span style=\"color: #A020F0\">topo<\/span><\/pre><pre style=\"font-style:oblique\">  Name            Size            Bytes  Class     Attributes\r\n\r\n  topomap1       64x3              1536  double              \r\n  topomap2      128x3              3072  double              \r\n\r\n<\/pre><h3>Loading Some Data<a name=\"5\"><\/a><\/h3>\r\n   <p>Assuming I have enough memory, I can easily <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2010a\/techdoc\/ref\/load.html\"><tt>load<\/tt><\/a> the data from a MAT-file.  But sometimes I don't want to load everything, perhaps because some of the variables are large.\r\n      And if I don't need them, why use the memory and clutter my workspace?  I can choose to load selected variables only.\r\n   <\/p>\r\n   <p>NOTE: <i>Before anyone asks, I can't currently (R2010a) load part of an array in MATLAB; and yes, that's on our enhancement list.<\/i><\/p>\r\n   <p>So let me load in just the <tt>topomap*<\/tt> variables.  I have two ways to manage this.  First\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">load <span style=\"color: #A020F0\">topo<\/span> <span style=\"color: #A020F0\">topom*<\/span>\r\nwhos<\/pre><pre style=\"font-style:oblique\">  Name            Size            Bytes  Class     Attributes\r\n\r\n  topomap1       64x3              1536  double              \r\n  topomap2      128x3              3072  double              \r\n\r\n<\/pre><p>and you can see that the variables <tt>topomap1<\/tt> and <tt>topomap2<\/tt> have been loaded into my workspace.  There have been many discussions on the MATLAB <a >newsgroup<\/a> that \"poofing\" variables into the workspace, especially inside a function, is a poor idea.  Instead, I can load them into\r\n      a known variable.  To do so, I must use the functional form of <tt>load<\/tt> instead of the command form.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">mydata = load(<span style=\"color: #A020F0\">'topo'<\/span>,<span style=\"color: #A020F0\">'topom*'<\/span>)<\/pre><pre style=\"font-style:oblique\">mydata = \r\n    topomap1: [64x3 double]\r\n    topomap2: [128x3 double]\r\n<\/pre><p>Now I have a known variable (<tt>mydata<\/tt>) which is a <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2010a\/techdoc\/ref\/struct.html\"><tt>struct<\/tt><\/a>. <tt>mydata<\/tt> has fields with the names of the selected variables from the <tt>topo.mat<\/tt> MAT-file.\r\n   <\/p>\r\n   <p>Here's more <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2010a\/techdoc\/import_export\/braietb-1.html\">information<\/a> to help you as you manage loading your data into MATLAB.\r\n   <\/p>\r\n   <h3>Do You Load Data Selectively?<a name=\"8\"><\/a><\/h3>\r\n   <p>Do any of you use some of these techniques for managing and loading selected portions of your data?  I'd love to hear more\r\n      <a href=\"https:\/\/blogs.mathworks.com\/loren\/?p=237#respond\">here<\/a>.\r\n   <\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_f9420f8d92aa47a5973a95b86d31013c() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='f9420f8d92aa47a5973a95b86d31013c ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' f9420f8d92aa47a5973a95b86d31013c';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        author = 'Loren Shure';\r\n        copyright = 'Copyright 2010 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add author and copyright lines at the bottom if specified.\r\n        if ((author.length > 0) || (copyright.length > 0)) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (author.length > 0) {\r\n                d.writeln('% _' + author + '_');\r\n            }\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n      \r\n      d.title = title + ' (MATLAB code)';\r\n      d.close();\r\n      }   \r\n      \r\n-->\r\n<\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_f9420f8d92aa47a5973a95b86d31013c()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n            the MATLAB code \r\n            <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; 7.10<br><\/p>\r\n<\/div>\r\n<!--\r\nf9420f8d92aa47a5973a95b86d31013c ##### SOURCE BEGIN #####\r\n%% What Data Is Available?\r\n% Yes, I know, data *are*, but the title just sounded terrible that way.\r\n%\r\n% Ever wonder what data you have stored in some files, particularly MATLAB\r\n% MAT-files?  Sometimes I'd like to know what's there without making the\r\n% commitment to load the data.  Fortunately, there's a good way to\r\n% accomplish this in MATLAB programmatically, and another good way when\r\n% viewing the Current Folder.  I will show you the programmatic way.\r\n%% Files to Look at\r\n% Let's first identify some files to look at.  I happen to know that we\r\n% have some data for demos stored on the MATLAB\r\n% <https:\/\/www.mathworks.com\/help\/releases\/R2010a\/techdoc\/ref\/path.html\r\n% |path|>.  These include the files |durer.mat|, |seamount.mat|, and\r\n% |clown.mat|.\r\n%% Peek Inside\r\n% Let's take a peek inside the seamount data.  I can do this using a\r\n% variant of the \r\n% <https:\/\/www.mathworks.com\/help\/releases\/R2010a\/techdoc\/ref\/whos.html\r\n% |whos|> function.\r\nwhos -file seamount.mat\r\n%%\r\n% And what's lurking inside |topo.mat|?\r\nwhos -file topo\r\n%%\r\n% Notice in this case, there are 4 variables, including 2 starting with the\r\n% name \"topomap\".  Suppose I want to find all the variables with names\r\n% beginning with \"topom\".  I can use the wildcard character \"*\".\r\nwhos topom* -file topo\r\n%% Loading Some Data\r\n% Assuming I have enough memory, I can easily \r\n% <https:\/\/www.mathworks.com\/help\/releases\/R2010a\/techdoc\/ref\/load.html\r\n% |load|> the data from a MAT-file.  But sometimes I don't want to load\r\n% everything, perhaps because some of the variables are large. And if I\r\n% don't need them, why use the memory and clutter my workspace?  I can\r\n% choose to load selected variables only.  \r\n%\r\n% NOTE: _Before anyone asks, I can't currently (R2010a) load part of an \r\n% array in MATLAB; and yes, that's on our enhancement list._\r\n%\r\n% So let me load in just the |topomap*| variables.  I have two ways to\r\n% manage this.  First\r\nload topo topom*\r\nwhos\r\n%%\r\n% and you can see that the variables |topomap1| and |topomap2| have been\r\n% loaded into my workspace.  There have been many discussions on the MATLAB\r\n% <http:\/\/ newsgroup> that\r\n% \"poofing\" variables into the workspace, especially inside a function, is\r\n% a poor idea.  Instead, I can load them into a known variable.  To do so,\r\n% I must use the functional form of |load| instead of the command form.\r\nmydata = load('topo','topom*')\r\n%%\r\n% Now I have a known variable (|mydata|) which is a\r\n% <https:\/\/www.mathworks.com\/help\/releases\/R2010a\/techdoc\/ref\/struct.html\r\n% |struct|>. |mydata| has fields with the names of the selected variables\r\n% from the |topo.mat| MAT-file.\r\n%\r\n% Here's more <https:\/\/www.mathworks.com\/help\/releases\/R2010a\/techdoc\/import_export\/braietb-1.html\r\n% information> to help you as you manage loading your data into MATLAB.\r\n%% Do You Load Data Selectively?\r\n% Do any of you use some of these techniques for managing and loading\r\n% selected portions of your data?  I'd love to hear more\r\n% <https:\/\/blogs.mathworks.com\/loren\/?p=237#respond here>.\r\n\r\n##### SOURCE END ##### f9420f8d92aa47a5973a95b86d31013c\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\n   \r\n      Yes, I know, data are, but the title just sounded terrible that way.\r\n      \r\n      Ever wonder what data you have stored in some files, particularly MATLAB MAT-files?  Sometimes I'd... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/loren\/2010\/06\/25\/what-data-is-available\/\">read more >><\/a><\/p>","protected":false},"author":39,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[15,11,13],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts\/237"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/users\/39"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/comments?post=237"}],"version-history":[{"count":1,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts\/237\/revisions"}],"predecessor-version":[{"id":2554,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts\/237\/revisions\/2554"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/media?parent=237"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/categories?post=237"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/tags?post=237"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}