how can I save the value of a text area from app designer into a file .txt?
조회 수: 9 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (2개)
Kojiro Saito
2018년 12월 19일
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
Jeffrey
2020년 2월 4일
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
2020년 2월 5일
Hi Jeffrey,
write_txt_file was a funciton that the questioner (Gabriele Penna) wrote in the above question.
lakrifi yahya
2021년 7월 2일
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 !!
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!