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 to make the textscan command skip the line with texts

Status
Not open for further replies.

talhacae

Newbie level 1
Joined
May 22, 2011
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,286
hi,
anybody know how the textscan can be used to skip the text line in file and carry on reading the data in a sequence. I have to read a file with numeric data but the text appears randomly in the file. i have to skip and read the next line.

But one thing i have observed that once the textscan reads the text file i keeps on returning empty array.

here the code:

fname = input('Enter Data File Name:','s');
fid=fopen(fname,'r');
r=zeros(300,8);

for j=1:300

C = textscan(fid, '%d', 8);
m = cell2mat(C);

r1=m';
r(j,:)=r1;
j=j+1;
if j==300
break;
end;

end
plot(r(2:300,1));

So, the code reads the data up to 300 samples, but the text appears 2 or 3 times for two rows. Once the textscan reads the text it gives error and returns empty array. The data is like that:
-12 -42 40 -75 -70 -110 -153 -140
-4 -55 -18 -144 -130 -183 -234 -207
17 -22 -41 -161 -131 -190 -221 -179
-62 -92 16 -89 -71 -96 -129 -109
-38 -64 89 -17 -31 -35 -95 -73
-80 -71 43 -68 -65 -94 -147 -134
-45 -59 -11 -124 -122 -189 -216 -180
-62 -69 -42 -157 -128 -195 -228 -186
-65 -81 53 -42 -32 -45 -88 -49
-79 -84 117 19 19 -3 -53 -35
-39 -52 44 -54 -46 -76 -121 -105
-22 -32 1 -119 -118 -166 -194 -161
HEART_RATE 54
LEAD_OFF_STATUS 1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0
-4 -12 -38 -148 -114 -172 -199 -174
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top