Working with the MIT arrhythmia database annotations: how can I convert the characters into numbers?
11 次查看(过去 30 天)
显示 更早的评论
I work with MIT arrhythmia database and I want to group the annotations given for each beat in 5 classes, such as:
N={'N','L','R','e','j'}; %non_ectopic_beat
S={'A','a','J','S'}; %supra_ventricular_ectopic_beat
V={'V','E'}; %ventricular_ectopic_beats
F={'F'}; %Fusion_beat
non_beats={'+','/','f','Q'};
How can I search into the annotation files of each ECG signal and replace the letter from those 5 groups with numbers from 1 to 5?
For example, when I have any of the non-ectopic beats ('N', 'L','R','e', or 'j' ) I want to have the label 1. For the secong class ('A','a','J','S') I want to have label 2 and so on.
I am also opened to other suggestion, as my goal is to append these annotatios to the feature set that I extracted from these signals.
The annotations files are in 'atr' format and I read them using the WFDB toolbox:
[ann,anntype]=rdann('100','atr');
%ann has the location of the R peak and anntype has the annotation of each heartbeat
anntype =
2274×1 char array
'+'
'N'
'N'
'N'
'N'
'N'
'N'
'N'
'A'
'N'
'N'
'N'
...
4 个评论
回答(1 个)
Shadaab Siddiqie
2021-2-25
From my understanding you want to replace few strings to few particular numbers. Here is the code which might help you.
content = fileread( 'ann.txt' ) ;
content = strrep( content, 'N', '1' ) ;
content = strrep( content, 'L', '1' ) ;
content = strrep( content, 'V', '3' ) ;
content = strrep( content, '+', '5' ) ;
fId = fopen( 'MyData_updated.txt', 'w' ) ;
fwrite( fId, content ) ;
fclose( fId ) ;
Then you can read new file as numbers.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!