Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

Problem with reading files in Matlab

Status
Not open for further replies.

confi999

Junior Member level 3
Joined
Dec 12, 2005
Messages
25
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,503
reading files matlab

Hi,

I have a formatted data file (obtained from fortran) which has 1 column and 24000 rows. The values are like

-0.8736252526127E-9
-0.1928287267367E-11
0.28373737626278E-12
etc etc.

I have tried to read these data in matlab using the following command :

fid=fopen('filename');
[b,count]=fscanf(fid,'%25f',[1,inf]);
fclose(fid);

I have tried with %g as well as the format specifier. Then I have also tried to use 'load' command of matlab. In all the cases I end up with wrong values of the data in the vector. I get somethiing like 0.0001, -0.0005, 0.003, etc .... These are far larger values compared to those in the source file.

Can anyone advise me - how I can read those data successfully in matlab.
Thank you.
 

wpchan05

Full Member level 4
Joined
Feb 16, 2006
Messages
213
Helped
20
Reputation
40
Reaction score
4
Trophy points
1,298
Activity points
2,392
read in data file in matlab

confi999 said:
Hi,

I have a formatted data file (obtained from fortran) which has 1 column and 24000 rows. The values are like

-0.8736252526127E-9
-0.1928287267367E-11
0.28373737626278E-12
etc etc.

I have tried to read these data in matlab using the following command :

fid=fopen('filename');
[b,count]=fscanf(fid,'%25f',[1,inf]);
fclose(fid);

I have tried with %g as well as the format specifier. Then I have also tried to use 'load' command of matlab. In all the cases I end up with wrong values of the data in the vector. I get somethiing like 0.0001, -0.0005, 0.003, etc .... These are far larger values compared to those in the source file.

Can anyone advise me - how I can read those data successfully in matlab.
Thank you.


try execute the following command before reading the text file

>> format long

that might help.
 

confi999

Junior Member level 3
Joined
Dec 12, 2005
Messages
25
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,503
reading file in matlab

Thank you for the reply - that really helped to some extent. But,

some of the data from my file are like:
-9.822387897877512E-009
-8.718508242883641E-009
-7.412423106618656E-009
-6.024806197201503E-009
-4.681798286449183E-009
-3.482646037397550E-009
-2.479999539418316E-009
-1.677888998136245E-009


and after reading matlab is showing these as

-0.000982238789788
-0.000871850824288
-0.000741242310662
-0.000602480619720
-0.000468179828645
-0.000348264603740
-0.000247999953942
-0.000167788899814

So all the data seem to be read as *******E-04 instead of *******E- 09

Can anyone help me overcome this. Thank you very much.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top