problem from reading data from a .txt file

Hello I have 20000 data located in a .txt file.this data genarated by randi function of matlab..
my notepad is looks like this
Columns 1 through 20
160 7 121 126 83 106 41 6 183 132 68 105 42 62 194 214 122 73 194 187
Columns 21 through 40
16 253 10 199 249 106 79 154 34 46 116 83 122 11 6 .......more
now I need to read data from this .txt.. my code is
fid = fopen('D:\data_1.txt');
A = fscanf(fid, '%g', [2 inf]);
fclose(fid);
X=reshape(A,20000,1);
but I am getting error on RESHAPE function...it says "To RESHAPE the number of elements must not change."
in workspace A is blank..whats going wrong?

답변 (1개)

Jing
Jing 2012년 10월 31일

0 개 추천

Hi,
Can you try to use the default setting of FSCANF function?
Like A=fscanf(fid,'%g');

댓글 수: 4

tusu
tusu 2012년 10월 31일
No that also gives error...How to read data from a file when the data in the notepad are 1*20000 double format?
A = fscanf(fid, '%g', [2 inf]);
This is wrong.For this to work your data should have been in below format:
Columns 1 through 20000
160 7 121 126 83 106 41 6 183 132 68 105 42 62 194 214 122 73 194 187........100(20000th element)
tusu
tusu 2012년 10월 31일
Yup I think so....what to do now which command should I use...the problem is creating "Columns 1 through 20" and so on...any suggestion?
tusu
tusu 2012년 10월 31일
any suggestions for reading data from following files

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

카테고리

도움말 센터File Exchange에서 Workspace Variables and MAT Files에 대해 자세히 알아보기

질문:

2012년 10월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by