I'm currently working in MatLab AppDesigner. I am trying to get MatLab to download the contents of an editable Text Area as a specific type of file (.cfile) and save this file to a specific location. The user should be able to edit the code of the file in the Text Area, and then click a button which will cue MatLab to download the file as a .cfile and save it to a specific location on the user's device. Initially, the Text Area will contain a default code setup, which the user can modify before downloading. I am relatively new to MatLab; does anyone know how I could do this? Thanks!

댓글 수: 10

Rik
Rik 2018년 8월 2일
Download means it is loaded from a web page of some sort, but the rest of your description sounds like it's just saving a file.
Hanna Al-Kowsi
Hanna Al-Kowsi 2018년 8월 2일
Yeah essentially I just want the user to be able to save the contents of the Text Area as a specific file type.
Rik
Rik 2018년 8월 2일
Then I would create a figure with a text field and a save button. The callback function for that uicontrol button would then use get to load the contents of the text field to a cell array. You can use uiputfile to ask te user for a file location. Then the writing of the file depends on your file format.
Hanna Al-Kowsi
Hanna Al-Kowsi 2018년 8월 2일
I'm sorry, I'm really new to MatLab, could you type out some of the code for me?
Hanna Al-Kowsi
Hanna Al-Kowsi 2018년 8월 2일
I have the text file and the save button created, but I'm not sure how to correctly format the code to download the file and save it.
Rik
Rik 2018년 8월 2일
I mentioned several functions. Did you read the corresponding documentation pages?
Hanna Al-Kowsi
Hanna Al-Kowsi 2018년 8월 3일
편집: Hanna Al-Kowsi 2018년 8월 3일
I read through the documentation pages for each function, and this is my code right now:
function saveButtonPushed(app,event)
ctxt = get(app.cfile, 'Value');
uiputfile(ctxt, 'custom.cfile');
But every time I try to run it, rather than generating ctxt, the Text Area value, as the file, it opens the save file dialogue box and lists the lines of text in the Text Area as different file types? Like this:
Do you know what I'm doing wrong/how to resolve this issue?
Rik
Rik 2018년 8월 3일
The uiputfile function asks the user for a location to save your file to, it doesn't write the file. With the writing of the file we can't help you because you didn't give a description of the file format.
Hanna Al-Kowsi
Hanna Al-Kowsi 2018년 8월 3일
What information about file format is required? The file type is a .cfile, and essentially should just be the lines of text from the Text Area.
Rik
Rik 2018년 8월 3일
If it is just a text file with some extension, you should be able to find plenty of examples how to write the contents of a cell to a text file. I could find what type of file it would be, as there isn't even a filext page.

댓글을 달려면 로그인하십시오.

 채택된 답변

Walter Roberson
Walter Roberson 2018년 8월 3일

0 개 추천

savedir = '.'; %current directory? You should probably adjust this to a known location or use uigetdir()
outfile = fullfile(savedir, 'custom.cfile');
ctxt = get(app.cfile, 'Value');
[fid, message] = fopen(outfile, 'wt');
if fid < 0
fprintf('Failed to save file "%s" because: %s"\n', outfile, message);
return
end
fprintf(fid, '%s\n', ctxt{:});
fclose(fid)

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Downloads에 대해 자세히 알아보기

제품

릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by