MATLAB: Can the Import File component in the Report Generator 1.3 (R13) accept a variable containing a file name as input

componentfilefilenamegeneratorimportMATLAB Report Generatorreportvariable

I am attempting to import a file into my report using the Import File component, but the file name changes each time I run the report. I want to be able to specify a file name in a workspace variable, but when I do this, Report Generator fails to import my file. The help documentation seems to indicate that the Import File component will only work if I hard code a valid file name. I would like to know if there is any way to work around this limitation.

Best Answer

  • This enhancement has been incorporated in Release 14 Service Pack 2 (R14SP2). For previous product releases, read below for any possible workarounds:
    There are two possible ways to work around the limitation that the file name must be hard-coded into the Import File component in the Report Generator. The first is to use an "Evaluate MATLAB Expression" component to execute the command "type(x)", where x is the variable that contains the file name, and select the "Display command window output in report" option for that component. This is an easy workaround, but the file you are trying to import will be displayed to the Command Window while the report is being generated. This could slow down the generation if the file is very large.
    The second alternative is to create your own component based on the Import File component that can accept the name of a variable as the file name and display the file as you want. Chapter 5 of the Report Generator documentation describes how to create your own components and provides an example you can use as a template. This workaround will not be as easy as the first, but if you are planning on using this functionality repeatedly and do not want to display all the files you are including in the report on the Command Window, it may save time in the long run.