how can I save the value of a text area from app designer into a file .txt?

7 visualizzazioni (ultimi 30 giorni)
I have to save the content of a text area into a specific folder as a file .txt.
I am able to do it in matlab but I can manage to pass the function in app designer.
this is the function I used in matlab for a similar issue (to pass a vector into a file.txt) :
function write_txt_file(vector,filename,directory)
%
%Function that writes a vector with NUMERICAL DATA to a file with a certain
%filename in a certain directory
%
% vector: vector/matrix variable containing the data to be written
% filename: name of file to be saved, i.e., [imagename '-LI.txt']
% directory: directory where the file should be saved
[r, c]=size(vector);
if ~isfolder(directory)
mkdir(directory)
end
if directory(end) == '/'
directory = directory(1:end-1);
end
if strcmp(filename(end-3:end),'.txt')
fp=fopen([directory '/' filename],'w');
else
fp=fopen([directory '/' filename '.txt'],'w');
end
if ~isempty(vector)
for i=1:r
for j=1:c
fprintf(fp,'%f ',vector(i,j));
end
fprintf(fp,'\r\n');
end
end
fclose(fp);
end

Risposte (2)

Kojiro Saito
Kojiro Saito il 19 Dic 2018
Attached is a sample app designer file.
If button is pressed, a number written in text area will be save as a text file.
% Button pushed function: SaveButton
function SaveButtonPushed(app, event)
vec = str2double(app.TextArea.Value{:});
write_txt_file(vec, 'test', '.');
end
You can access to the characters by app.TextArea.Value and, in order to fit them to your write_text_file function, I've converted characters to double.
  2 Commenti
Jeffrey
Jeffrey il 4 Feb 2020
Hi Kojiro,
Thanks for answering this question where where does write_txt_file come from? I can't seem to get the attached file to run.
Thanks,
Jeff
Kojiro Saito
Kojiro Saito il 5 Feb 2020
Hi Jeffrey,
write_txt_file was a funciton that the questioner (Gabriele Penna) wrote in the above question.

Accedi per commentare.


lakrifi yahya
lakrifi yahya il 2 Lug 2021
Hello everone, i want to save data from appDesigner to text file
Please, someone can help me like to save a table on a textfile
Thanks !!

Categorie

Scopri di più su Develop Apps Using App Designer in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by