MATLAB: ARRANGING TEXT FILE

text filetextscan

Hi,
I am working on a dynamic analysis. I am trying to run ANSYS on MATLAB. Therefore I have to change some value in my text file. Text file is large but i need to change e few line as follows;
loadvari47rotz(2,1,1) = *0.174532925199433* ??CHANGING_LINE-1
loadvari47rotz(3,1,1) = *0.349065850398866* ??CHANGING_LINE-2
I want to change above value for each step. Text file is at attachment and you can find changing lines CTRL+F "??CHANGING_LINE-1" and "??CHANGING_LINE-1".
I will be so happy if you help me.
Best Regards, Ahmet TATAR

Best Answer

Here is an example, and then we can tailor the solution to your needs from there:
content = fileread( 'TEST.txt' ) ;
content = regexprep( content, '(?<=_loadvari47rotz\(2,1,1\) = )\S+', sprintf( '%f', 0.123 )) ;
content = regexprep( content, '(?<=_loadvari47rotz\(3,1,1\) = )\S+', sprintf( '%f', 0.456 )) ;
fId = fopen( 'TEST_updated.txt', 'w' ) ;
fwrite( fId, content ) ;
fclose( fId ) ;
This can easily be updated for matching/replacing other parts, looping through files, etc.