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

44 ビュー (過去 30 日間)
RN
RN 2020 年 2 月 12 日
コメント済み: David Szwer 2021 年 7 月 23 日
I need to save notes in the text area to a specific location. How to save the data using app designer?

採用された回答

Siriniharika Katukam
Siriniharika Katukam 2020 年 2 月 18 日
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 件のコメント
Peter de Goot
Peter de Goot 2020 年 6 月 23 日
This appears to remove any paragraph characters. How to retain?

サインインしてコメントする。

その他の回答 (2 件)

kuldeep vaishnav
kuldeep vaishnav 2020 年 5 月 24 日
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 2021 年 2 月 19 日
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 件のコメント
David Szwer
David Szwer 2021 年 7 月 23 日
'a.txt' is the filename. Replace that with the filename you want, including the full path.

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by