Hi! I need to write data from matlab workspace to a .txt file. This is not the problem. However, writing a string followed by a numerical value on the same line I've not managed to solve.
The attached file(txt-fil) depict the current .txt file with the faulty line highlited. The below code produces said file, including the faulty line, which is caused by the code entry "…'Nsecs='… and the entry below "….'Amodl='… The two code lines needs altering, but I don't know how. The end result should look like the second attachment(txt-fil_2), where Nsecs and Amodl is stacked with their corresponding numerical values.
filename = 'modell_septic.txt'; fid = fopen(filename,'w+'); if fid ~= -1 fprintf(fid, [oppirom 'Modellfil for SEPTIC' '\r\n']); fprintf(fid, [oppirom 'Nsecs=' ' ' '%f' 1 '\r\n']); fprintf(fid, [oppirom 'Amodl=' ' ' 200 '\r\n']); fprintf(fid,'%f %f %f %f \r\n',mat); fclose(fid);
Any help or ideas are appreciated. Thanks!
Best Answer