using fprintf instead of dlmwrite to make a .txt file
Show older comments
Hello everyone :)
I'm having a bit of a problem. As the title suggests I'm trying to use fprintf instead of dlmwrite to make a .txt file. I was asked to 'write explicit CR LF – line endings \r\n in c string formatting notation used by matlab'. However I'm not really sure what that means!
I have a few matrices that I need to put into a .txt file. I had it done using dlmwrite, however I was asked to use fprintf or sprintf instead. I've gone onto the Mathworks pages for them and read everything but I just can't wrap my head around it. Could someone help guide me in the right direction? I'm not looking for the answer, just some guidance.
My code, using dlmwrite:
AA=[100079,1000,length(Tri.nodes2)];
BB=['PROJCS["British_National_Grid",GEOGCS["GCS_OSGB_1936",DATUM["D_OSGB_1936",SPHEROID["Airy_1830",6377563.396,299.3249646]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",400000],PARAMETER["False_Northing",-100000],PARAMETER["Central_Meridian",-2],PARAMETER["Scale_Factor",0.999601272],PARAMETER["Latitude_Of_Origin",49],UNIT["Meter",1]'];
CC=[length(Tri.triangles),3,21];
DD=[(1:length(Tri.triangles))',Tri.triangles];
dlmwrite('bathymetry.txt',AA,'delimiter',' ','precision',6);
dlmwrite('bathymetry.txt',BB,'-append',...
'delimiter',' ','roffset',0,'precision',6);
dlmwrite('bathymetry.txt',Tri.nodes2,'-append',...
'delimiter',' ','roffset',0,'precision',6);
dlmwrite('bathymetry.txt',CC,'-append',...
'delimiter',' ','roffset',0,'precision',6);
dlmwrite('bathymetry.txt',DD,'-append',...
'delimiter',' ','roffset',0,'precision',6);
I've also attached a picture of why I need to use the other method!
Thanks :)
Accepted Answer
More Answers (1)
Categories
Find more on Text Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!