Saving textfiles in a other folder
显示 更早的评论
Hello there,
I try to open a text file in a other folder, replace "," with "." and to close and save.
It works, but the new text is saved in the folder of my matlabscript. But I want, that it saved there, where it tooks the textfile to manipulate it, just overwrite the old one.
Maybe someone can help me. Thanks!
addpath('E:\Data\Test\X')
testfiledir = 'E:\Data\Test\X';
matfiles = dir(fullfile(testfiledir, '*.txt'));
% A=dir ('*.txt')
B=matfiles(1).name;
FileName=B;
Data = fileread(FileName);
Data = strrep(Data, ',', '.');
FID = fopen(FileName, 'w');
fwrite(FID, Data, 'char');
fclose(FID);
% type FileName; hier nicht benötigt
M= readmatrix(FileName);
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!