在txt文件印刷我有一個輸入.txt文件這樣「NULL」而不是0利用Matlab
head1 head2 head3 head3
0.004 5.104175 -1.651492 0.074480
0.015 5.104175 -1.327670 0.087433
0.025 5.104175 -1.181950 0.093910
...
,我想減去第一行於以下所有的行中相同的文件,即是,印刷這樣的.txt文件:
0 0 0 0
0.011 0 -0.323825 -0.012953
...
這裏是我的代碼:
for i = 1:length(x) %read all the files contained in folder_inp
%%check file extensions
[pathstr,name,ext] = fileparts(x(i).name);
%%if it is a text file...
if strcmp('.txt',ext)
s = importdata(strcat(folder_inp,'\',x(i).name));
init = s.data(1,:);
for k=1:length(s.data)
if s.data(k,:) == init
s.data(k,:) = zeros(1,length(s.data(k,:)));
else
s.data(k,:) = s.data(k,:)-init;
end
end
fid = fopen(strcat(folder_out,'\',name,'.txt'), 'w');
formatSpecs = '%20s %20s %20s %20s \r';
for j = 1:length(s.data)
if j == 1
fprintf(fid,formatSpecs,'head1','head2','head3','head4');
elseif j==2
fprintf(fid,'\n') ;
else
fprintf(fid,formatSpecs,s.data(j,1),s.data(j,2),s.data(j,3),s.data(j,4));
end
end
fclose(fid);
end
end
everithing工作正常,exept事實次而不是0代碼打印空字符。有什麼建議麼?
輸入文件中的符號a,b,c等代表什麼?我想你實際上是在減去數字?你能發佈一個輸入文件的工作示例嗎? – Dennis
是的。我編輯了問題 – drSlump