How can I find and replace strings in a text file?

Hi,
I've written my table to a text file; however, I need this text file to be delimited by three spaces, which MATLAB doesn't allow using the 'writetable' function. Therefore, I must find and replace each instance of the ' ' string with the ' ' string in my text file. I also need to replace the first line of my text file with another string. How can I accomplish this?
I've tried to use textscan for this, but I keep getting the following error:
snip3Capture.JPG
For visual clarity, here is what I am trying to accomplish with my text file:
snip1Capture.JPG(original)
snip2Capture.JPG(goal)

 Réponse acceptée

Skip the writetable.
filename = 'goal.txt';
[fid, msg] = fopen(filename, 'wt');
if fid < 0
error('Failed to open output file "%s" because "%s"', filename, msg);
end
fprintf(fid, '"Time" "X" "Y" "Pressure"\n');
fprintf(fid, '%g %g %g %g\n', YourTable{:,:}.' ); %transpose is needed
fclose(fid);

Plus de réponses (0)

Catégories

En savoir plus sur Characters and Strings dans Centre d'aide et File Exchange

Produits

Version

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by