I have many files in one folder like the two examples attached. I want to change the number formed in columns 14-21 of any row that starts with "SO" "R " "TS" or "SH" by "2.335". Then write the numbers back to the row in the same file. Below is what I've tried so far:
clear; clc; close all; delta = 2.335;% delta is the change in elevation
lst = dir('*.txt'); for n = 1:size(lst,1) t = lst(1).name; fid = fopen(t); tline = fgets(fid); while ischar(tline) tline = fgetl(fid); if tline(1) == 'S'& tline(2)== 'O' disp(tline(15:21)); elev = str2num(tline(15:21)); elev = elev + delta; elev = num2str(elev) end end end
Thank you.
Best Answer