How to read a file unrecongnized to Matlab

hi, i am working on implementing the ECG on my DSP kit. i have stored the file using the provided software but its extension is ".ecg". Matlab of course does not read it directly...
If a open it in Matlab directory as OPEN AS TEXT, it opens. Then the data is shown to me as values from 8 channels of ECG. It has 8 numericals values in a spaced single row. And there are around 8000 rows with occasionally english text for heart rate and leads off status.
So is there a way i can read it?? Thanks.

Answers (2)

You can use textscan() function to read it. Some other functions are textread(),dlmread(). Try it yourself first.

1 Comment

I did what you have suggested. And i got the following results: I used textscan cause that seemed appropriate. Now the textscan make a cell and i would need an array to further plot and separate the data. Also it make the cell only up the first english text appears. So is there a way around or am i using wrong command after all...??

Sign in to comment.

If you have a mix of numbers and text and the text can appear at any line in the file, then you have to parse the data line by line. See for example the procedure in this Question

8 Comments

i have written the code and the error is keeps on coming... i don;t know the what is wrong with the code...
fname = input('Enter Data File Name:','s');
fid=fopen(fname,'r');
j=1;
r=zeros(60,8);
for j=1:60
C = textscan(fid, '%d', 8);
m = cell2mat(C);
r1=m';
r(j,:)=r1;
j=j+1;
end
Error it give is ....
??? Improper assignment with rectangular empty matrix.
Error in ==> readECG at 12
r(j,:)=r1;
When you get to the line that has text, textscan() with the '%d' format is not going to be able to read the number and is going to return an empty array.
Thanks Walter, i am able to correct the error. Now i am trying to add code to above one, that somehow skip the text and keeps on reading the data in the file. Cause i just used the data up to 60 samples just before the text appears in the code.
If you know the number of lines of valid data, then you can pass textscan the number of times to repeat the format. For example,
C = textscan(fid, repmat('%d',1,8), 60,'CollectOutput',1);
r = C{1};
Yes i know, but the thing is that the appearance of text is random...and the total number of samples is also random i.e depends on duration of ECG taken from a person.
Also can you tell me how i can use textscan to skip text cause once it reads the text no matter what i do it gives the empty array. I want it to read the text and next time it starts from the next line... Thanks.
How do you want to deal with those text? Can you simply ignore them and would that impact your numeric data? Post a short set of data with that scenario and we can help you.
fgetl() to read the line, after which you could start another textscan()
the data is of the form below. And it would not hurt to store the heart rate. But right now the my main agenda is to read the numerical values. The thing is that the text appears randomly in the data.
-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
-39 -52 44 -54 -46 -76 -121 -105

Sign in to comment.

Categories

Products

Asked:

on 10 Jun 2011

Community Treasure Hunt

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

Start Hunting!