Importdata won't work with this txt file

1 次查看(过去 30 天)
Hello, I want to take a txt file that contains headerlines and then a matrix of numbers that represents an image. I cannot get importdata to read the file, I get
??? Error using ==> importdata at 214 Unable to load file. Use TEXTSCAN or FREAD for more complex formats.
I also can't get textscan to work. I have attached the file
//-----------------------------------Begining of file----------
File : C:\
Title:
Date : 17/06/2011
Detector 31, NSCG Surface 1: 1mm sample
Size 1.000 W X 1.000 H Millimeters, Pixels 200 W X 200 H, Total Hits = 158280
1 2 3
1 9.781E-003 1.676E-002 2.619E-002
2 2.224E-002 2.936E-002 3.852E-002
//--------------------END OF File
note, there are tabs at the begining of lines and there are 200 rows and columns of data. I dont need to read in the column or row numbers
  1 个评论
Jason
Jason 2011-6-20
I've just checked and my program that creates these txt files was set with the txf file encoding as "Unicode". When I switch it to ANSI, import data and textscan work. The problem is that I have all my data in this UNICODE format. Can importdata or textscan work with this?

请先登录,再进行评论。

回答(1 个)

Gerd
Gerd 2011-6-20
Hi Jason,
I would use the textscan command to extract the data. By using
fid = fopen('Data.txt')
tmp = textscan(fid,'%s%f%f%f')
fclose(fid)
you will get a cell array of data. Now you can extract the data row by row using
cell2mat(tmp(index))
Now you are able to extract whatever you want out of your data. I cannot test this script in detail but I am pretty sure with some examinations on the data it should work.
If you do have problem please post.
Gerd
  8 个评论
Jason
Jason 2011-6-20
Could I email it to you? as i don't see any upload facility here.
Gerd
Gerd 2011-6-20
Sure you can do but I will be out of office until tomorrow.
bwts.tre at googlemail dot com

请先登录,再进行评论。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by