“uigetfile” function will not work here because it is used for opening files, not saving. “uiputfile” function is used for saving files.
- Firstly, place the desired PPT or PDF file in the same folder as the .mlapp file.
- Then, add the following code to the download button’s callback function:
% Button pushed function: Button
function ButtonPushed(app, event)
% Desired document
filename = 'mydoc.pdf';
% Getting the app's folder and then the desired file
appFolder = fileparts(mfilename('fullpath'));
sourceFile = fullfile(appFolder, filename);
% Asking the user where to save the file
[file, path] = uiputfile({'*.pdf;*.pptx','Documents (*.pdf, *.pptx)'}, ...
'Save As', filename);
if isequal(file,0)
return; % If user cancels
end
% Copying the file to the user's chosen location
destination = fullfile(path, file);
try
copyfile(sourceFile, destination);
uialert(app.UIFigure, 'Document downloaded successfully!', 'Success');
catch ME
uialert(app.UIFigure, ['Failed to download: ' ME.message], 'Error');
end
end
Through this, you will be able to achieve the required functionality in your app.
To create and deploy a corresponding web app for your app, refer to the following documentation:
For more information regarding the used functions, refer to the following documentation:
For more help, you may refer to a similar MATLAB answer:
Hope this helps!
