How can i save the text area characters to a text file in app designer?

19 vues (au cours des 30 derniers jours)
RN
RN le 12 Fév 2020
Commenté : David Szwer le 23 Juil 2021
I need to save notes in the text area to a specific location. How to save the data using app designer?

Réponse acceptée

Siriniharika Katukam
Siriniharika Katukam le 18 Fév 2020
Hi
To load text entered in text area of an app to a text file, you can do this in the callback function of text area.
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
Hope this helps!
  1 commentaire
Peter de Goot
Peter de Goot le 23 Juin 2020
This appears to remove any paragraph characters. How to retain?

Connectez-vous pour commenter.

Plus de réponses (2)

kuldeep vaishnav
kuldeep vaishnav le 24 Mai 2020
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
David Szwer le 19 Fév 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 commentaires
David Duque
David Duque le 22 Juil 2021
how can I choose a path to save the txt file?
David Szwer
David Szwer le 23 Juil 2021
'a.txt' is the filename. Replace that with the filename you want, including the full path.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Data Import and Export dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by