Before I try to apply textread to the .txt file, I have already split up the file from a large text file to smaller text files using a script which is successful in its execution and uses functions fopen, fgetl.
Large Text File -> Small Text File 1, Small Text File 2, Small Text File 3
Output of Small Text File 1:
Run Lat Long Time
2 1 13 3
2 3 3 3
3 3 5 12
From the split up text file -- small text file 1 -- which is in column format, I apply textread and returns a mixture of random (scattered) data from the text file (random sample of data from col2 and col3).
In the code: the function is the basic:
[col1 col2] = textread('smallfile.txt', '%d %d');
Output Return: 3 12 13 5
Not what is in Col1 = 2 2 3
I have tried to fix it by checking ANSI encoding and applying rt in my opening function. But no success.
Thanks,
Amanda

4 件のコメント

José-Luis
José-Luis 2012 年 8 月 19 日
編集済み: José-Luis 2012 年 8 月 19 日
Is there a particular reason you are using textread? The importdata function might make your life easier. Also, some example data would help in understanding the problem.
Walter Roberson
Walter Roberson 2012 年 8 月 19 日
Are you using textread() or textscan() ?
Amanda
Amanda 2012 年 8 月 19 日
編集済み: Amanda 2012 年 8 月 19 日
I have update the question to be clearer. I'm trying to get the data in columns for plotting.
Walter Roberson
Walter Roberson 2012 年 8 月 19 日
textread() is going to read all the data on the line, not only as many columns as you provide %d for.

サインインしてコメントする。

 採用された回答

José-Luis
José-Luis 2012 年 8 月 19 日
編集済み: José-Luis 2012 年 8 月 19 日

0 投票

You could use:
[A,' ', 1] = importdata('myFile.txt);
%And the variables you want:
col1 = A.data(:,1);
col2 = A.data(:,2);
For more info
help importdata
And if you need low level routine:
help fscanf
Cheers!

3 件のコメント

Amanda
Amanda 2012 年 8 月 19 日
Definitely works with the integer data. Not working well with string data. I know that I didn't put this in my example but I have one significant column of string data which I would like to pull in as a column. I happy with the integer column data. Thanks.
José-Luis
José-Luis 2012 年 8 月 19 日
Look inside A.textdata, all text data should be in there. More details in:
help importdata
Cheers!
Amanda
Amanda 2012 年 8 月 19 日
Perfect Columns. Excellent!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by