-1

Based on this question Append image to PDF report , I was wondering is it possible to snapshot the axes in app designer in order to save them in PDF report?

I tried the code below but I get an error

Error:

Undefined function 'getSnapshotImage' for input arguments of type 'matlab.ui.control.UIAxes'.

Code:

function ButtonPushed(app, event)

    import mlreportgen.dom.*;
    import mlreportgen.report.*

    folder = 'E:/';
    file = 'shapes2.png'
    fullFileName = fullfile(folder, file);

    I= imread(fullFileName); 
    level = graythresh(I);
    BW = imbinarize(I,level);
    imshow( BW ,'Parent', app.UIAxes) 


    filter = {'*.pdf'};
    [file, pathPDF] = uiputfile([folder,filter{1}])


    if file ~= 0 
        d = Document('myPDF','pdf');
        d.OutputPath = [pathPDF,file];
        figure = app.UIAxes;
        snap = Image(getSnapshotImage(app.UIAxes,d));
        img1 = Image(fullFileName); 
        img1.Style = [img1.Style {ScaleToFit}];
        close(d);     
    end 
end
alirazi
  • 159
  • 8

1 Answers1

1

The error mentions that you are using the incorrect input type. When this type of error is displayed, you should check the function signature to check what it expects.

I suggest you familiarize yourself with the Mathworks documentation and learn to use the help browser directly from MATLAB (right click on function name, then Help on selection).

You will find that the function getSnapshotImage accepts, as a first argument, a mlreportgen.report.Figure object, and not a matlab.ui.control.UIAxes object.

Reference: https://www.mathworks.com/help/rptgen/ug/mlreportgen.report.figure.getsnapshotimage.html#d120e37424

Paolo
  • 21,270
  • 6
  • 38
  • 69