I am trying to restrict a text file by only keeping lines that contain 'M' in the first column.
I wrote the code below, except 'M' cannot be used in str2double. Would there be an alternative way to write this? Code below:
clear allfidi = fopen('BTM.txt','rt');Glxc = textscan(fidi, '%s', 'Delimiter','|');frewind(fidi)Glxcs = textscan(fidi, '%s', 'EndOfLine','\r\n');fclose(fidi);dlen = 2*fix(length(Glxc{:})/2); % Set Row Length
Glxcr = reshape(Glxc{:}(1:dlen), 2, [])'; % Reshape & Transpose
LIdx= (str2double(Glxcr(:,2))<=1813.1) & (str2double(Glxcr(:,1))='M')% Reshape & TransposeNewGlxc = Glxcs{:}(LIdx,:); % Rows Of New Array
fido = fopen('vcc18M.txt','wt')fprintf(fido, '%s\n', NewGlxc{:});fclose(fido)
Best Answer