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.

[SOLVED] importing data from text file to Matlab

Status
Not open for further replies.

mazdak

Junior Member level 3
Junior Member level 3
Joined
Jun 21, 2010
Messages
26
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,283
Activity points
1,499
Hi,
I want to import the result of the fft in Hspice *.lis file to Matlab, here is a part of the text file that i wanna use (the fft_mag is important for me now):
...
frequency frequency fft_mag fft_mag fft_phase
index (hz) (db) (deg)

205 10.0098x 0. 1.0000 -90.0948
410 20.0195x -74.5959 186.2961u 93.9587
615 30.0293x -74.2619 193.6005u -2.9902
820 40.0391x -73.5943 209.0668u -124.8979
1025 50.0488x -81.0959 88.1462u 117.2375
1230 60.0586x -89.3502 34.0794u 80.9893
1435 70.0684x -85.3732 53.8689u -195.5287m
1640 80.0781x -91.3661 27.0205u -75.9253
1845 90.0879x -100.0618 9.9291u -95.4531
...
I wrote this function to do this :
data = fscanf(fid,'%c');
loc2 = findstr('(deg)',data);
i=68;
for k=1:8
A=data(loc2+i:loc2+i+61);
temp=sscanf(A,'%*s %*s %*s %s %*s');
DATA(k)=temp;
i=i+63;
end
fclose(fid);
-------------------------
I was successful until finding the fft_mag value of each row, but I can't store them in any kind of variable. for this part of code the error is:
Subscripted assignment dimension mismatch.

Error in ==> readtext at 18
DATA(k)=temp;
can anyone help me? with correcting this code or giving me ideas how to it?
thanks in advance
 

the problem is that I want matlab to do this automatically, not by me with copy pasting. the load syntax simply loads whole data from *.lis file, I want a small part of it :D
moshkelet chie too hspice?
 

ok, I found a way finally, I put it here with explanations for those who may need this in the future:

%open the file with fopen
fid=fopen(file address);
%define DATA
DATA=[];
while(1)
line = fgetl(fid);%read line by line
if feof(fid), break, end; %until the end of file
%check if you reached the desired line in whole file
if(strcmp(line, ' frequency frequency fft_mag fft_mag fft_phase'))
%from now on we need the data
% read column headers
C_text = textscan(line, '%s', 5);
% read numeric data
line = fgetl(fid);%skip the line 'index (hz) (db) (deg)'
line = fgetl(fid);%skip the empty line
for i=1:9 % we need to import the next 9 lines
line = fgetl(fid);
DATA = [DATA;textscan(line, '%s %s %s %s %s')];%save everything %as 'string', we can convert them to numbers (with str2double for example) if %needed
end
end
end
 
Last edited by a moderator:
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top