MATLAB: How can i read second column from a txt file in matlab txt files in matlab here is the link of the file. https://www.physionet.org/atm/mitdb/100/atr/0/10/rdann/annotations.txt Best Answer [Filename,FilePath]=uigetfile('\\Address\*.txt','Load File');FileName=fullfile(FilePath,Filename);NoofCol=7;% Total no of col. in ur file Format=repmat('%s',1,NoofCol);fid=fopen(FileName,'rt');Header=fgetl(fid);% to delete first line (You can use this line as title for data plotting)data_cell=textscan(fid,Format,'HeaderLines',1,'CollectOutput',1);fclose(fid);data=data_cell{1};SecCol=str2double(data(:,2));Hope the above will help you Related SolutionsMATLAB: I want to delete all the headerlines and delimiters from the data in the below attached text file The best solution is probably to read your entire file as text, then remove the header lines, then parse them with textscan. MATLAB: How to add to txt file from certain point One way would be the following: fid_in = fopen('inFile.txt', 'r') ; fid_out = fopen('outFile.txt', 'w') ; cnt = 0 ; while ~feof(fid_in) if cnt == 7, cnt = 1 ; else cnt = cnt + 1 ; end fprintf(fid_out, '%s %d\r\n', fgetl(fid_in), cnt) ; end fclose(fid_in) ; fclose(fid_out) ; Related QuestionConcatenate data using fgetsStore the for result to txt file using dlmwriteMultiple loop do not loop
Best Answer