How can I save matrix to .txt, .xslx, and .pdf file selectable by the user using dialog box in App Designer?

4 views (last 30 days)
I try to figure out to save my output files from App Designer to .txt or excel or .pdf format which should be selectable by the user via a file saving dialog box.
I run the below code when only "writetable" is accessible and I get the .txt file successfully.
Likewise, when only "xlswrite" or "publish" is accessible then I get an excel file successfully.
But I need to make it selectable. How can I fix it?
function RelativeErrorButtonPushed(app, event)
filter = {'*.txt', 'Text File'; ...
'*.xslx', 'XSLX File'; ...
'*.pdf', 'PDF Document';...
'*.*', 'All Files'};
[file, path] = uiputfile(filter, 'File Selection', 'Error_Percent');
app.filename = fullfile(path, file);
assignin ("base","filter",filter);
% Create variable names
Head1 = app.Error_Percent(:,1);
Head2 = app.Error_Percent(:,2);
Head3 = app.Error_Percent(:,3);
Head4 = app.Error_Percent(:,4);
Head5 = app.Error_Percent(:,5);
% Create a table with the data and variable names
T = table(Head1, Head2, Head3, Head4, Head5, app.Error_Percent);
% Write data to text file
writetable(T,app.filename,'Delimiter', ' ', "Encoding", 'UTF-8');
% xlswrite(app.filename, app.Error_Percent);
% publish(app.filename, app.Error_Percent);
end

Answers (1)

Ishaan Mehta
Ishaan Mehta on 4 Mar 2024
Hi Nimet
As I understand, you wish to allow the user to pick out a specific format for export, from a list of allowed options. This is a typical use-case for creating a dropdown in the MATLAB App Designer UI. You can add a dropdown through the "uidropdown" component.
Simply drag a "Drop Down" component from the "Component Library" panel, and add various options like "TXT", "XLS", "PDF", etc. as required.
Now, add a "Button" component, and in the button's "ButtonPushedFcn" callback, define the logic to check for the "app.DropDown.Value" (assuming the dropdown component is "app.DropDown") and use an if-else block or a "switch-case" statement to call the export logic according to the option selected by the user.
With this done, the user interface should look something like this:
For more information about the "drop-down" component, refer to:
Hope this helps!

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!