Effacer les filtres
Effacer les filtres

Importdata won't work with this txt file

4 vues (au cours des 30 derniers jours)
Jason
Jason le 20 Juin 2011
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 commentaire
Jason
Jason le 20 Juin 2011
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?

Connectez-vous pour commenter.

Réponses (1)

Gerd
Gerd le 20 Juin 2011
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 commentaires
Jason
Jason le 20 Juin 2011
Could I email it to you? as i don't see any upload facility here.
Gerd
Gerd le 20 Juin 2011
Sure you can do but I will be out of office until tomorrow.
bwts.tre at googlemail dot com

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by