Matlab fprintf function does not create newlines

I tried to remove some lines from a file using following commands.

fData = textread('s0001_rem.hea', '%s','delimiter','\n','whitespace', '');
fData ([20 19 18])=[];
fid=fopen('s0001_rem.hea', 'w');
for i=1:length(fData) fprintf(fid,'%s', '\n', fData {i});
end
fid=fclose(fid);

But after running this command, I opened the file to check and it does not show newlines anymore. It shows all the information in a single line and instead of a newline, it shows \n.

I'm new to Matlab, so I have no idea how to solve this problem.Checked everywhere on the internet but had no luck.Please help me. I'm using Matlab R2014b on MacOS.

Note

.hea file is a kind of a .txt file with some information. It exactly works like a text file.

1 Answer

Instead of a newline, it shows \n

fprintf(fid,'%s', '\n', fData {i});

Try putting the \n inside the first argument, as follows:

fprintf(fid,'%s\n', fData {i});
0

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like