Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics 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.

How can i read two columns data from a text file with Matlab

Status
Not open for further replies.

ahmad_abdulghany

Advanced Member level 4
Advanced Member level 4
Joined
Apr 12, 2005
Messages
1,206
Helped
102
Reputation
206
Reaction score
22
Trophy points
1,318
Location
San Jose, California, USA
Activity points
11,769
I have a text file that contains two colomns of row data, only numbers

here's a sample of it:

Code:
2.00000e-10       2.12723e-01      
 2.80000e-10       2.12723e-01      
 3.60000e-10       2.12723e-01      
 4.40000e-10       2.12723e-01      
 5.20000e-10       2.12723e-01      
 6.00000e-10       2.12723e-01      
 6.80000e-10       2.12723e-01      
 7.60000e-10       2.12723e-01      
 8.40000e-10       2.12723e-01      
 9.20000e-10       2.12723e-01      
 1.00000e-09       2.12723e-01      
 1.08000e-09       2.12723e-01      
 1.16000e-09       2.12723e-01      
 1.24000e-09       2.12723e-01      
 2.84000e-09       2.12723e-01      
 2.92000e-09       2.12723e-01      
 3.00000e-09       2.12723e-01      
 3.08000e-09       2.12723e-01      
 3.16000e-09       2.12723e-01      
 3.24000e-09       2.12723e-01      
 3.32000e-09       2.12723e-01      
 3.40000e-09       2.12723e-01      
 3.48000e-09       2.12723e-01      
 3.56000e-09       2.12723e-01      
 3.64000e-09       2.12723e-01

I tried to use import data wizard, and load() function, but it always returns the last elements equal zeros (in first colomn)

I tried to write this function:
Code:
a=[];
fid=fopen('trial.dat','r');
while 1
    tline=fgetl(fid);
    if ~ischar(tline),break,end;
    a=[a;[tline]];
end
fclose(fid)

But i failed, because tline is not a two colomns vectro, i.e. its contents are many characters actually,
you can check that by typing:
Code:
tline'  % transpose
in the matlab command...

Can anyone help ?

Here's the file i want to read its elements out in a matrix..

Thanks alot in advance,
Ahmad,
 

Re: How can i read two columns data from a text file with Ma

Alhamdulillah, i did it !

I wanted to plot it..and succeeded alhamdulillah :)

Here's the code:
Code:
b=[];    %initializes a null matrix
fid = fopen('trial.dat', 'r');
while 1
    tline=fgetl(fid);
    if ~ischar(tline),break, end
    a=str2num(tline);
    b=[b;a];
end;
fclose(fid);
plot(b(:,1),b(:,2)); % this is to plot first colomn of b versus second colomn

You can try it!
I hope it help anyone,
Regards,
Ahmad,
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top