Clear Filters
Clear Filters

error in opening MIT ecg database

1 view (last 30 days)
hello,
I want read and plot ECG signal downloaded from MIT data base (.dat) i use the following codes:
clear all
clc
close all
[filename, pathname] = uigetfile('*.dat', 'Open file .dat');% only image Bitmap
if isequal(filename, 0) || isequal(pathname, 0)
disp('File input canceled.');
ECG_Data = [];
else
fid=fopen(filename,'r')
end;
time=10;
f=fread(fid)
Orig_Sig=f(1:length(f));
%plot(Orig_Sig(1:2:length(f)))
plot(Orig_Sig(1:2:4000))
i get the following error:
Error using fread Invalid file identifier. Use fopen to generate a valid file identifier.
how i can read these data?
thank in advance
  1 Comment
Star Strider
Star Strider on 28 Jan 2017
If you are using the PhysioBank ATM to access the files, it is much easier to request the MATLAB ‘.mat’ file than the other formats to use them in MATLAB. Then you can just load them. Be sure to download the accompanying ‘.info’ file as well, since it has the sampling frequency and other information you will need to process your signals

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 28 Jan 2017
fd = fopen( fullfile(pathname, filename), 'r')
  2 Comments
anas qazaz
anas qazaz on 28 Jan 2017
thank Mr Walter my data stored in E drive , bin file, the data file name 102.dat how i can use your code?
Walter Roberson
Walter Roberson on 28 Jan 2017
[filename, pathname] = uigetfile('*.dat', 'Open file .dat');
if isequal(filename, 0) || isequal(pathname, 0)
disp('File input canceled.');
ECG_Data = [];
else
fid = fopen( fullfile(pathname, filename), 'r')
time = 10;
f = fread(fid)
Orig_Sig=f(1:length(f));
plot(Orig_Sig(1:2:4000))
end
You are requesting to open a file that is not in your current directory. uigetfile() returns the directory and filename in different outputs -- so it does know which directory you requested but the directory is not built into the filename output. You then tried to open using just the filename output without putting together the information uigetfile() returned about the directory.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!