An efficient way to import data containing letters and numbers?

6 views (last 30 days)
Hello,
I am trying to generate some netcdf files with data sets containing numerical values along with data flags represented by numbers. Here is what some data looks like:
01108431895 487X 445X 599X 662X 726X
01108431896 484X 535X 568X 702E 778X
01108431897 465X 563X 666X 657X 701X
01108431898 531E 514E 634E 614E 752E
Is there any way to import this data and use it to create 3-d arrays so it looks exactly the way it does above, with the letter flags?
Thanks, Dan
  6 Comments
Image Analyst
Image Analyst on 20 Jan 2012
Your subject says you're trying to import data, but your body says you're trying to generate a netcdf file. Which is it? Read in or write out?
By the way, there is a netcdf listing in the help you know, with all kinds of things you can do with netcdf files.
Dan
Dan on 20 Jan 2012
Sorry for the unclear wording, I am trying to read in the data from a text file and then create 3-d arrays to use to write netcdf files.
I don't need help creating the netcdf file, just properly importing the data.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 20 Jan 2012
fid = fopen('YourFileName', 'rt');
indata = textscan(fid, '%s%s%s%s%s%s');
fclose(fid);
Now indata{1} will be a cell array of strings which is the first column, indata{2} will be a cell array of strings which is the second column, and so on.
If everything is in a netcdf file instead of a text file, the import methods would not be the same. I am not familiar enough with netcdf to advise.
  1 Comment
Dan
Dan on 20 Jan 2012
Thanks Walter, for some reason I couldn't get textscan to work for me before. This is exactly what I needed!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!