How to Publish from App Designer with a Push Button?
2 views (last 30 days)
Show older comments
Hi Guys!
I'm use MATLAB R2019a.
General question: Is it possible to Publish from the App Designer? (with a Push Button)
This is my Code:
function ButtonReportgeneriereninternPushed(app, event)
% Fahrzeugprofil
app.Dateiname=evalin('base','Dateiname'); % Get my Values from the Worksapce
% Fahrleistungsprofil
app.Projekt=evalin('base','Projekt'); % Get my Values from the Worksapce
app.Type=evalin('base','Type'); % Get my Values from the Worksapce
% there are more Values
options_pdf_nocode.format = 'pdf'; % FORMAT .pdf
options_pdf_nocode.outputDir = 'C:\Users\Florian\OneDrive\Masterarbeit_RMMV\011_Matlab_Excel'; %output
%options_pdf_nocode.stylesheet= ;
options_pdf_nocode.createThumbnail = true;
%options_pdf_nocode.figureSnapMethod = ;
%options_pdf_nocode.imageFormat = ;
%options_pdf_nocode.maxHeight = ;
%options_pdf_nocode.maxWidth = ;
%options_pdf_nocode.useNewFigure = true;
%options_pdf_nocode.catchError = true;
%options_pdf_nocode.codeToEvaluate = ;
%options_pdf_nocode.maxOutputLines = inf;
options_pdf_nocode.evalCode = true;
options_pdf_nocode.showCode = false;
publish('AppDesignerPublish.m',options_pdf_nocode) % Publish durchführen
winopen AppDesignerPublish.pdf % .pdf öffnen
end
% my Publish Function
function [] = AppDesignerPublish(Dateiname,Projekt,Type,Datum,angefordertvonBenutzer,Benutzer,SetupUmgebung,v_W,mue_R,f_R,Temp_E,Hoehe_E,alpha_,phi)
%%
% *Fahrzeugprofil:*
disp (string(Dateiname))
%%
% *Fahrleistungsprofil*
disp (['Projekt: ', string(Projekt)])
disp (['Fahrzeugtyp: ', string(Type)])
% this is function is longer with the same type of writing
end
This is the Error:
Not enough input arguments.
Error in AppDesignerPublish (line 17)
disp (['Projekt: ', string(Projekt)])
If it is not possible to Publish from the App Designer, is it possible to generate a Report with the Report Generator?
If it is only possible with the Report Generator is there some other (free) option?
Thank you for your reply.
0 Comments
Answers (3)
Zenin Easa Panthakkalakath
on 15 May 2019
Hi Florian,
It is possible to use 'publish' function inside App Designer. From the error report, it appears to be that the 'AppDesignerPublish.m' contains a function that requires an argument, which was not passed. As 'publish' function generates a report that contains the code and the output of the code, the code needs to be run in order to produce the output. While running the code, it appears to be that certain argument is missing and hence it can not complete the process.
I hope this explanation helps.
Regards,
Zenin
0 Comments
Mary Abbott
on 28 May 2019
Hi Florian,
I agree with Zenin's answer. The error is produced because the AppDesignerPublish function is not being supplied with its required arguments. You can experiment with the codeToEvaluate option of the publish function to supply the neccessary arguments. However, keep in mind that the publish function evaluates the given code in the base workspace, not in your App Designer callback's workspace.
Using Report Generator will allow easier creation and formatting. The following is an example push button callback that generates a report using MATLAB Report Generator:
function ButtonReportgeneriereninternPushed(app, event)
% Your supplied code to get values:
% Fahrzeugprofil
app.Dateiname=evalin('base','Dateiname'); % Get my Values from the Worksapce
% Fahrleistungsprofil
app.Projekt=evalin('base','Projekt'); % Get my Values from the Worksapce
app.Type=evalin('base','Type'); % Get my Values from the Worksapce
% there are more Values
% Example code:
% Import the Report and DOM API package
import mlreportgen.report.*
import mlreportgen.dom.*
% Create a PDF report
rpt = Report("myReport", "pdf");
% Add a heading to the report
h = Heading3(app.Dateiname);
add(rpt, h);
% Add content to the report
p1 = Paragraph("Projekt " + string(app.Projekt));
add(rpt, p1);
p2 = Paragraph("Fahrzeugtyp " + string(app.Type));
add(rpt, p2);
% (Continue adding content.)
% Close and view the report
close(rpt);
rptview(rpt);
end
This example uses only headings and paragraphs, but depending on the data you are reporting, you may want to use other components. See the following link for more content options:
0 Comments
See Also
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!