{"id":11609,"date":"2020-06-26T09:00:22","date_gmt":"2020-06-26T13:00:22","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=11609"},"modified":"2020-06-26T11:06:53","modified_gmt":"2020-06-26T15:06:53","slug":"convert-tdms","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2020\/06\/26\/convert-tdms\/","title":{"rendered":"Convert TDMS"},"content":{"rendered":"<div xmlns:mwsh=\"http:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n   <introduction>\r\n      <p><a href=\"http:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/3208495\">Sean<\/a>'s pick this week is <a href=\"http:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/44206\">ConvertTDMS<\/a> by <a href=\"http:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/18971\">Brad Humphreys<\/a>.\r\n      <\/p>\r\n   <\/introduction>   \r\n   <p>I'm asked occasionally by LabVIEW users who want to use MATLAB for analysis if it's possible to read TDMS files.  I typically\r\n      recommend looking at our <a href=\"https:\/\/www.mathworks.com\/products\/data-acquisition.html\">data acquisition products<\/a> to stream the data from a National Instruments device directly into MATLAB.  However, this isn't always an option as many\r\n      files already exist or the infrastructure has been built in LabVIEW.\r\n   <\/p>\r\n   <p>The <tt>convertTDMS<\/tt> function makes this possible and returns a structure with TDMS data.  Optionally, it can also save the data to a MAT file\r\n      so you don't have to read or convert it twice.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">s = convertTDMS(false, <span style=\"color: #A020F0\">'filename'<\/span>, fullfile(pwd, <span style=\"color: #A020F0\">'exampleFiles'<\/span>, <span style=\"color: #A020F0\">'simple_test.tdms'<\/span>))<\/pre><pre style=\"font-style:oblique\">\r\n\r\nConverting 'simple_test.tdms'...\r\n\r\nConversion complete.\r\n\r\ns = \r\n  struct with fields:\r\n\r\n         FileName: 'simple_test.tdms'\r\n       FileFolder: 'C:\\Documents\\MATLAB\\potw\\ConvertTDMS\\exampleFiles'\r\n    SegTDMSVerNum: 4713\r\n    NumOfSegments: 1\r\n             Data: [1&times;1 struct]\r\n<\/pre><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">plot(s.Data.MeasuredData(3).Data)\r\nxlabel(<span style=\"color: #A020F0\">'Sample'<\/span>)\r\ntitle(s.Data.MeasuredData(3).Name)<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/mainConvertTDMS_01.png\"> <p>I also like how this file has evolved over time with many different contributing authors and the project migrated to GitHub.<\/p>\r\n   <h3>Comments<a name=\"4\"><\/a><\/h3>\r\n   <p>Give it a try and let us know what you think <a href=\"http:\/\/blogs.mathworks.com\/pick\/?p=11609#respond\">here<\/a> or leave a <a href=\"http:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/44206#comments\">comment<\/a> for Brad.\r\n   <\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_7b52958e0339486781ee457ea17cb2bc() {\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='7b52958e0339486781ee457ea17cb2bc ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 7b52958e0339486781ee457ea17cb2bc';\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 = 'Sean de Wolski';\r\n        copyright = 'Copyright 2020 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_7b52958e0339486781ee457ea17cb2bc()\"><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; R2020b<br><\/p>\r\n<\/div>\r\n<!--\r\n7b52958e0339486781ee457ea17cb2bc ##### SOURCE BEGIN #####\r\n%% Convert TDMS\r\n%\r\n% <http:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/3208495 Sean>'s pick this week is\r\n% <http:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/44206 ConvertTDMS> by\r\n% <http:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/18971 Brad Humphreys>.\r\n% \r\n\r\n%%\r\n% I'm asked occasionally by LabVIEW users who want to use MATLAB for\r\n% analysis if it's possible to read TDMS files.  I typically recommend\r\n% looking at our <https:\/\/www.mathworks.com\/products\/data-acquisition.html\r\n% data acquisition products> to stream the data from a National Instruments\r\n% device directly into MATLAB.  However, this isn't always an option as\r\n% many files already exist or the infrastructure has been built in LabVIEW.\r\n%\r\n% The |convertTDMS| function makes this possible and returns a structure\r\n% with TDMS data.  Optionally, it can also save the data to a MAT file so\r\n% you don't have to read or convert it twice.\r\n\r\ns = convertTDMS(false, 'filename', fullfile(pwd, 'exampleFiles', 'simple_test.tdms'))\r\n\r\n%%\r\nplot(s.Data.MeasuredData(3).Data)\r\nxlabel('Sample')\r\ntitle(s.Data.MeasuredData(3).Name)\r\n\r\n%%\r\n%\r\n% I also like how this file has evolved over time with many different\r\n% contributing authors and the project migrated to GitHub.\r\n\r\n%% Comments\r\n% \r\n% Give it a try and let us know what you think\r\n% <http:\/\/blogs.mathworks.com\/pick\/?p=11609#respond here> or leave a\r\n% <http:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/44206#comments\r\n% comment> for Brad.\r\n%\r\n \r\n\r\n##### SOURCE END ##### 7b52958e0339486781ee457ea17cb2bc\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/mainConvertTDMS_01.png\" onError=\"this.style.display ='none';\" \/><\/div><p>\r\n   \r\n      Sean's pick this week is ConvertTDMS by Brad Humphreys.\r\n      \r\n      \r\n   I'm asked occasionally by LabVIEW users who want to use MATLAB for analysis if it's possible to... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2020\/06\/26\/convert-tdms\/\">read more >><\/a><\/p>","protected":false},"author":87,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/11609"}],"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\/87"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=11609"}],"version-history":[{"count":4,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/11609\/revisions"}],"predecessor-version":[{"id":11621,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/11609\/revisions\/11621"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=11609"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=11609"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=11609"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}