How can I save matrix to .txt, .xslx, and .pdf file selectable by the user using dialog box in App Designer?
조회 수: 3 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (1개)
Ishaan Mehta
2024년 3월 4일
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!
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!