This is a very basic question, but since I'm new to Matlab, I'm struggling to find a good way to do so. I just want to print some concatenated strings to screen and to a text file. Matlab is "eating" the \n !!
str1 = sprintf('Line 1\n');
str2 = sprintf('Line 2\n');
finalStr = strcat(str1,str2);
% Print on screen
fprintf('%s',finalStr );
% Result: Line 1Line 2. What happened to the \n ?? !!!!
% Print on file
[curPath,name,ext] = fileparts(mfilename('fullpath'));
infoPath = fullfile(curPath,'MyFile.txt');
fid = fopen(infoPath,'w'); % Write only, overwrite if exists
fprintf(fid,finalStr);
fclose(fid);
I also need to save finalStr to a text file. What I'm missing here?
strcat:For character array inputs, strcat removes trailing ASCII white-space characters: space, tab, vertical tab, newline, carriage return, and form feed.You have a trailing newline. Usehorzcatinstead.