Importdata won't work with this txt file

조회 수: 4 (최근 30일)
Jason
Jason 2011년 6월 20일
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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Large Files and Big Data에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by