Replacing elements of a text file
显示 更早的评论
Dear community, i already searched for my matter but i do not find any good reply. Btw, i have a text file "map.txt" composed by different letters in a 25x60 matrix.
And i need to rewrite this matrix in a new text file replacing all the letters different from "i" with an "e" (it's an academic exercise). I really have different difficulties loading the file.
My idea was using some code like this one:
filename='mappa.txt';
delimiterIn='';
headerlinesIn=25;
A=importdata(filename,delimiterIn,headerlinesIn);
[n,m]=size(A);
Aout=zeros(size(A));
for i=1:n
for j=1:m
if (A(i,j)==('I'))
Aout(i,j)=('X');
else
Aout(i,j)=('~');
end
end
end
disp=(Aout)
but it obviously doesn't work. Any suggestion? Kindly, A.
2 个评论
dpb
2015-10-5
importdata is for numeric, not character data.
Would need sample of the file to know precisely the input, but to do a simple character substitution, look at
doc strrep
Alberto Rizzo
2015-10-5
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Large Files and Big Data 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!