How can i save the text area characters to a text file in app designer?
Show older comments
I need to save notes in the text area to a specific location. How to save the data using app designer?
Accepted Answer
More Answers (2)
kuldeep vaishnav
on 24 May 2020
0 votes
value = app.TextArea.Value; % Value entered in textArea
f=fopen('a.txt','w');
formatSpec= "%s";
for i =1:length(value)
fprintf(f,formatSpec,value{i});
end
David Szwer
on 19 Feb 2021
Try using the writecell() function. As far as I can tell, although a TextArea's Value can be set in numerous different formats, when used as an output it always emerges as a cell array of character arrays (one line in each cell). writecell() turns this straight back into a multiline text file. Adapting Siriniharika Katukam's answer:
value = app.TextArea.Value; % Value entered in textArea
writecell(value, 'a.txt', 'QuoteStrings',false);
Matlab's documentation suggests that QuoteStrings is false by default; I found that it was true by default so you need to turn it off.
2 Comments
David Duque
on 22 Jul 2021
how can I choose a path to save the txt file?
David Szwer
on 23 Jul 2021
'a.txt' is the filename. Replace that with the filename you want, including the full path.
Categories
Find more on Develop Apps Programmatically 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!