MATLAB: How to change a specific part in a specific line in a text file

text file

Hi,
I have a txt file and I need to change specific numbers in specific lines,
line 131, a = 10
line 132, b = 30
is any way to change the above lines to:
a = 5
b = 60

Best Answer

contents = fileread('test.txt');
newa = 10;
newb = 123;
newcontents = regexprep(contents, {'^a\S*=\S*\d+', '^b\S*=\S*\d+'}, {sprintf('a = %d', newa), sprintf('b = %d', newb)});
fid = fopen('test_new.txt', 'wt');
fwrite(fid, newcontents);
fclose(fid);