I need to write data to a .txt file in MATLAB. I know how to write strings (fprintf) or matrices (dlmwrite), but I need something that can do both of them. I'll give an example below:
str = 'This is the matrix: ' ;
mat1 = [23 46 ; 56 67] ;
%fName
if *fid is valid*
fprintf(fid, '%s\n', str)
fclose(fid)
end
dlmwrite(fName, *emptymatrix*, '-append', 'delimiter', '\t', 'newline','pc')
dlmwrite(fName, mat1, '-append', 'newline', 'pc')
This works okay, but with a problem. The first line of the file is:
This is the matrix: 23,46
Which is not what I want. I want to see:
This is the matrix:
23 46
56 67
How can I solve this? I can't use a for loop and printf solution as the data i