Replace '+-" with '-' in a csv file

11 次查看(过去 30 天)
MD REZWANUR RAHMAN
MD REZWANUR RAHMAN 2021-6-28
回答: Chunru 2021-6-28
I have some data file in .csv format. In the data there are complex values like 3+-3i, but I want to replace all of this '+-' with '-'.

回答(1 个)

Chunru
Chunru 2021-6-28
% Read data
fid = fopen('yourfile.csv');
s = fscanf(fid, '%c', [1 inf]); % read all text from file
fclose(fid);
% Replace string
s = strrep(s, '+-', '-');
% Save data
fid = fopen('newfile.csv');
s = fprintf(fid, '%c', s); % read all text from file
fclose(fid);

类别

Help CenterFile Exchange 中查找有关 Data Import and Export 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by