{"id":12443,"date":"2021-07-11T21:00:22","date_gmt":"2021-07-12T01:00:22","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=12443"},"modified":"2021-07-14T09:06:04","modified_gmt":"2021-07-14T13:06:04","slug":"import-explorer-to-help-you-with-importing-table-data","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2021\/07\/11\/import-explorer-to-help-you-with-importing-table-data\/","title":{"rendered":"Import Explorer to help you with importing table data"},"content":{"rendered":"<div class = rtcContent><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><a href = \"https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/869871\"><span>Jiro<\/span><\/a><span>'s Pick this week is <\/span><a href = \"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/92468\"><span>Import Explorer for tables<\/span><\/a><span> by <\/span><a href = \"https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/7100334\"><span>Jan Studnicka<\/span><\/a><span>.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>When importing data as a table, you can use <\/span><a href = \"https:\/\/www.mathworks.com\/help\/matlab\/ref\/detectimportoptions.html\"><span style=' font-family: monospace;'>detectImportOptions<\/span><\/a><span> to customize how you bring in your data. You can choose to import specific columns, specify the data type of each column, specify how to treat missing values, and many more. <\/span><\/div><h3  style = 'margin: 15px 10px 5px 4px; padding: 0px; line-height: 18px; min-height: 0px; white-space: pre-wrap; color: rgb(60, 60, 60); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 17px; font-weight: 700; text-align: left; '><span>Import Explorer<\/span><\/h3><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Jan's entry is a visual tool to help with this customization. It also lets you save the output for <\/span><span style=' font-family: monospace;'>detectImportOptions<\/span><span> so that you can programmatically reproduce the operation. See this in action.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/pick\/files\/potw_ImportExplorer_1.gif\" width = \"808.8545654296876\" height = \"569\" alt = \"import_explorer.gif\" style = \"vertical-align: baseline\"><\/img><\/div><h3  style = 'margin: 15px 10px 5px 4px; padding: 0px; line-height: 18px; min-height: 0px; white-space: pre-wrap; color: rgb(60, 60, 60); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 17px; font-weight: 700; text-align: left; '><span>Programmatic Approach<\/span><\/h3><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>As a comparision, here's how you would do it programmatically from scratch.<\/span><\/div><div style=\"background-color: #F7F7F7; margin: 10px 0 10px 0;\"><div class=\"inlineWrapper outputs\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 1px solid rgb(233, 233, 233); border-bottom: 1px solid rgb(233, 233, 233); border-radius: 4px 4px 0px 0px; padding: 6px 45px 4px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >opts = detectImportOptions(<\/span><span style=\"color: rgb(170, 4, 249);\">\"airlinesmall.csv\"<\/span><span >)<\/span><\/span><\/div><div  style = 'color: rgb(64, 64, 64); padding: 10px 0px 6px 17px; background: rgb(255, 255, 255) none repeat scroll 0% 0% \/ auto padding-box border-box; font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; overflow-x: hidden; line-height: 17.234px; '><div class=\"inlineElement eoOutputWrapper embeddedOutputsVariableStringElement\" uid=\"D7536AE7\" data-testid=\"output_0\" data-width=\"1128\" data-height=\"438\" data-hashorizontaloverflow=\"false\" style=\"width: 1158px; max-height: 449px; white-space: pre; font-style: normal; color: rgb(64, 64, 64); font-size: 12px;\"><div class=\"textElement\" style=\"white-space: pre; font-style: normal; color: rgb(64, 64, 64); font-size: 12px;\"><div style=\"white-space: pre; font-style: normal; color: rgb(64, 64, 64); font-size: 12px;\"><span class=\"variableNameElement\" style=\"white-space: pre; font-style: normal; color: rgb(64, 64, 64); font-size: 12px;\">opts = <\/span><\/div><div style=\"white-space: pre; font-style: normal; color: rgb(64, 64, 64); font-size: 12px;\">  DelimitedTextImportOptions with properties:\r\n   Format Properties:\r\n                    Delimiter: {','}\r\n                   Whitespace: '\\b\\t '\r\n                   LineEnding: {'\\n'  '\\r'  '\\r\\n'}\r\n                 CommentStyle: {}\r\n    ConsecutiveDelimitersRule: 'split'\r\n        LeadingDelimitersRule: 'keep'\r\n       TrailingDelimitersRule: 'ignore'\r\n                EmptyLineRule: 'skip'\r\n                     Encoding: 'Shift_JIS'\r\n   Replacement Properties:\r\n                  MissingRule: 'fill'\r\n              ImportErrorRule: 'fill'\r\n             ExtraColumnsRule: 'addvars'\r\n   Variable Import Properties: Set types by name using setvartype\r\n                VariableNames: {'Year', 'Month', 'DayofMonth' ... and 26 more}\r\n                VariableTypes: {'double', 'double', 'double' ... and 26 more}\r\n        SelectedVariableNames: {'Year', 'Month', 'DayofMonth' ... and 26 more}\r\n              VariableOptions: Show all 29 VariableOptions \r\n\tAccess VariableOptions sub-properties using setvaropts\/getvaropts\r\n           VariableNamingRule: 'modify'\r\n   Location Properties:\r\n                    DataLines: [2 Inf]\r\n            VariableNamesLine: 1\r\n               RowNamesColumn: 0\r\n            VariableUnitsLine: 0\r\n     VariableDescriptionsLine: 0 \r\n\tTo display a preview of the table, use preview<\/div><\/div><\/div><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 1px solid rgb(233, 233, 233); border-bottom: 0px none rgb(0, 0, 0); border-radius: 0px; padding: 6px 45px 0px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >opts.VariableTypes([9 17 18]) = {<\/span><span style=\"color: rgb(170, 4, 249);\">'categorical'<\/span><span >};<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 0px none rgb(0, 0, 0); border-bottom: 0px none rgb(0, 0, 0); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >opts.SelectedVariableNames = opts.VariableNames([1 2 3 5 7 9 10 15 16 17 18]);<\/span><\/span><\/div><\/div><div class=\"inlineWrapper\"><div  style = 'border-left: 1px solid rgb(233, 233, 233); border-right: 1px solid rgb(233, 233, 233); border-top: 0px none rgb(0, 0, 0); border-bottom: 1px solid rgb(233, 233, 233); border-radius: 0px 0px 4px 4px; padding: 0px 45px 4px 13px; line-height: 17.234px; min-height: 18px; white-space: nowrap; color: rgb(0, 0, 0); font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace; font-size: 14px; '><span style=\"white-space: pre\"><span >data = readtable(<\/span><span style=\"color: rgb(170, 4, 249);\">\"airlinesmall.csv\"<\/span><span >,opts);<\/span><\/span><\/div><\/div><\/div><h3  style = 'margin: 15px 10px 5px 4px; padding: 0px; line-height: 18px; min-height: 0px; white-space: pre-wrap; color: rgb(60, 60, 60); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 17px; font-weight: 700; text-align: left; '><span>Import Tool<\/span><\/h3><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Of course, there is the <\/span><a href = \"https:\/\/www.mathworks.com\/help\/matlab\/ref\/importtool.html\"><span>Import Tool<\/span><\/a><span> that comes with MATLAB. You can do many of these customizations from the tool.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/pick\/files\/potw_ImportExplorer_2.png\" width = \"808.8545654296876\" height = \"472\" alt = \"import_tool.png\" style = \"vertical-align: baseline\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Jan's Import Explorer gives you a bit more options, since <\/span><span style=' font-family: monospace;'>detectImportOptions<\/span><span> provides those. In addition, Jan's tool works with multiple files, in which case it uses the <\/span><a href = \"https:\/\/www.mathworks.com\/help\/matlab\/ref\/datastore.html\"><span style=' font-family: monospace;'>datastore<\/span><\/a><span> function under the hood.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>A small request I have is for this to work with other file types, such as Excel files. Currently, this tool only works with CSV and TXT files.<\/span><\/div><h3  style = 'margin: 15px 10px 5px 4px; padding: 0px; line-height: 18px; min-height: 0px; white-space: pre-wrap; color: rgb(60, 60, 60); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 17px; font-weight: 700; text-align: left; '><span>Comments<\/span><\/h3><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Give this a try and let us know what you think<\/span><span> <\/span><a href = \"https:\/\/blogs.mathworks.com\/pick\/?p=12443#respond\"><span>here<\/span><\/a><span> <\/span><span>or leave a<\/span><span> <\/span><a href = \"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/92468#comment\"><span>comment<\/span><\/a><span> <\/span><span>for Jan.<\/span><\/div>\r\n<\/div><script type=\"text\/javascript\">var css = '\/* Styling that is common to warnings and errors is in diagnosticOutput.css *\/.embeddedOutputsErrorElement {    min-height: 18px;    max-height: 250px;    overflow: auto;} .embeddedOutputsErrorElement.inlineElement {} .embeddedOutputsErrorElement.rightPaneElement {} \/* Styling that is common to warnings and errors is in diagnosticOutput.css *\/.embeddedOutputsWarningElement{    min-height: 18px;    max-height: 250px;    overflow: auto;} .embeddedOutputsWarningElement.inlineElement {} .embeddedOutputsWarningElement.rightPaneElement {} \/* Copyright 2015-2019 The MathWorks, Inc. *\/\/* In this file, styles are not scoped to rtcContainer since they could be in the Dojo Tooltip *\/.diagnosticMessage-wrapper {    font-family: Menlo, Monaco, Consolas, \"Courier New\", monospace;    font-size: 12px;} .diagnosticMessage-wrapper.diagnosticMessage-warningType {    color: rgb(255,100,0);} .diagnosticMessage-wrapper.diagnosticMessage-warningType a {    color: rgb(255,100,0);    text-decoration: underline;} .diagnosticMessage-wrapper.diagnosticMessage-errorType {    color: rgb(230,0,0);} .diagnosticMessage-wrapper.diagnosticMessage-errorType a {    color: rgb(230,0,0);    text-decoration: underline;} .diagnosticMessage-wrapper .diagnosticMessage-messagePart,.diagnosticMessage-wrapper .diagnosticMessage-causePart {    white-space: pre-wrap;} .diagnosticMessage-wrapper .diagnosticMessage-stackPart {    white-space: pre;} .embeddedOutputsTextElement,.embeddedOutputsVariableStringElement {    white-space: pre;    word-wrap:  initial;    min-height: 18px;    max-height: 250px;    overflow: auto;} .textElement,.rtcDataTipElement .textElement {    padding-top: 3px;} .embeddedOutputsTextElement.inlineElement,.embeddedOutputsVariableStringElement.inlineElement {} .inlineElement .textElement {} .embeddedOutputsTextElement.rightPaneElement,.embeddedOutputsVariableStringElement.rightPaneElement {    min-height: 16px;} .rightPaneElement .textElement {    padding-top: 2px;    padding-left: 9px;}'; var head = document.head || document.getElementsByTagName('head')[0], style = document.createElement('style'); head.appendChild(style); style.type = 'text\/css'; if (style.styleSheet){ style.styleSheet.cssText = css; } else { style.appendChild(document.createTextNode(css)); }<\/script><a href=\"https:\/\/blogs.mathworks.com\/pick\/files\/potw_ImportExplorer.mlx\"><button class=\"btn btn-sm btn_color_blue pull-right add_margin_10\">Download Live Script<\/button><\/a>","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img src=\"https:\/\/blogs.mathworks.com\/pick\/files\/potw_ImportExplorer_1.gif\" class=\"img-responsive attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" decoding=\"async\" loading=\"lazy\" \/><\/div><p>Jiro's Pick this week is Import Explorer for tables by Jan Studnicka.When importing data as a table, you can use detectImportOptions to customize how you bring in your data. You can choose to import... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2021\/07\/11\/import-explorer-to-help-you-with-importing-table-data\/\">read more >><\/a><\/p>","protected":false},"author":35,"featured_media":12446,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[25,16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/12443"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=12443"}],"version-history":[{"count":2,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/12443\/revisions"}],"predecessor-version":[{"id":12461,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/12443\/revisions\/12461"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media\/12446"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=12443"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=12443"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=12443"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}