How to convert a .txt to .cdf ? Needed for Matlab that won't read txt as cdf

4 views (last 30 days)
I have a txt file that contains data in Common Data Format( CDF ). Matlab has functions to read this but it does not work. I assume because the extension is .txt and not .cdf. When I try to read it I get:
??? Error using ==> cdfinfoc Error issued from CDF library: "NOT_A_CDF_OR_NOT_SUPPORTED: Named CDF is corrupted or not supported by the current library version."
Error in ==> cdfinfo at 170 tmp = cdfinfoc(filename);
Error in ==> cdfread at 184 info = cdfinfo(filename);
Is there a way to trick Matlab and read it or do I need to transform somehow the txt into a .cdf? If so, how do I do that?
Thank you!

Answers (1)

dpb
dpb on 18 Mar 2014
I seriously doubt the extension has anything to do with it; the message indicates it's either not actually a .cdf file at all (one might expect it's just an ASCII file given the name?) or a later revision than the TMW library functions in your Matlab version.
But, you can prove this easily, just copy the file over to another with the wanted extension and try again -- but I'm betting you'll get the same result.
copyfile('yourcurrentfile',['yourcurrentfilebasename' '.cdf'])
You could, of course, just rename it but the above gives you a copy w/ the new name.
Iff'en as expected that has the same result, you might just try
edit 'yourcurrentfile'
or
type 'yourcurrentfile'
and see if it isn't just a plain ol' ordinary text file.

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!