How can I write data to a text file in a user-specified location that is already populated with a standard header?
Currently, I am working on an app that can successfully write 4 columns of data to a text file in a user-defined file location, at the push of a button. I am accomplishing this task using the following code:
% Button pushed function: ExporttotxtButton
function ExporttotxtButtonPushed(app, event)
[fn,pn] = uiputfile(‘.rdf’,’RoadProfile_bumpy_fl.rdf’,’RoadProfile_bumpy_fl.rdf’);
if isnumeric(fn) % user canceled
return % return early
end
% write the table to the user-specified file
writematrix(app.UITable.Data,fullfile(pn,fn),’Delimiter’,’tab’,’FileType’,’text’);
However, I have a very long string of text (about 47 lines of text…not included here to save space) that I would like to include as a header in the generated text file. The goal is to have the end result be a text file that already has the header populated with a standard 47 lines of text, and then write the matrix data below the header as I am already doing. I have tried using the following:
fprintf(fullfile(pn,fn),’%sn’,[‘long_string_of_text..’ …
‘creating new line each timen’…]
But, this doesn’t seem to work. Any help would be much appreciated. I can post the full text that I want to include in the header if that is necessary. Thank you.Currently, I am working on an app that can successfully write 4 columns of data to a text file in a user-defined file location, at the push of a button. I am accomplishing this task using the following code:
% Button pushed function: ExporttotxtButton
function ExporttotxtButtonPushed(app, event)
[fn,pn] = uiputfile(‘.rdf’,’RoadProfile_bumpy_fl.rdf’,’RoadProfile_bumpy_fl.rdf’);
if isnumeric(fn) % user canceled
return % return early
end
% write the table to the user-specified file
writematrix(app.UITable.Data,fullfile(pn,fn),’Delimiter’,’tab’,’FileType’,’text’);
However, I have a very long string of text (about 47 lines of text…not included here to save space) that I would like to include as a header in the generated text file. The goal is to have the end result be a text file that already has the header populated with a standard 47 lines of text, and then write the matrix data below the header as I am already doing. I have tried using the following:
fprintf(fullfile(pn,fn),’%sn’,[‘long_string_of_text..’ …
‘creating new line each timen’…]
But, this doesn’t seem to work. Any help would be much appreciated. I can post the full text that I want to include in the header if that is necessary. Thank you. Currently, I am working on an app that can successfully write 4 columns of data to a text file in a user-defined file location, at the push of a button. I am accomplishing this task using the following code:
% Button pushed function: ExporttotxtButton
function ExporttotxtButtonPushed(app, event)
[fn,pn] = uiputfile(‘.rdf’,’RoadProfile_bumpy_fl.rdf’,’RoadProfile_bumpy_fl.rdf’);
if isnumeric(fn) % user canceled
return % return early
end
% write the table to the user-specified file
writematrix(app.UITable.Data,fullfile(pn,fn),’Delimiter’,’tab’,’FileType’,’text’);
However, I have a very long string of text (about 47 lines of text…not included here to save space) that I would like to include as a header in the generated text file. The goal is to have the end result be a text file that already has the header populated with a standard 47 lines of text, and then write the matrix data below the header as I am already doing. I have tried using the following:
fprintf(fullfile(pn,fn),’%sn’,[‘long_string_of_text..’ …
‘creating new line each timen’…]
But, this doesn’t seem to work. Any help would be much appreciated. I can post the full text that I want to include in the header if that is necessary. Thank you. appdesigner MATLAB Answers — New Questions