Specify Path for Image in Report Generator
Show older comments
I have a pdf generated via MatLab Report Generator. I have a few remaining issues. I have spent days trying to resolve via search of this and other forums.
I am posting each issue individually.
This issue. Specify Path for Image in Report Generator
The following line is used in an Example Report. This works and finds the image in the local directory or in a directory via the addpath function.
img1 = Image(which('ngc6543a.jpg'));
Unfortunately, I will be supplied an Excel sheet which will supply a list of images with the full image path. There may be hundreds of images and directories in the list (and the database has more than 500,000 images). I am comfortable splitting the path and filename into different variables.
Simplified file list:
'C:\Dir1\ngc6543a.jpg'
'G:\Dir2\ngc6543a.jpg'
'S:\Dir1\SubDir\ngc6543a.jpg'
When I tried the following I always get an error.
img1 = Image(which('C:\Dir1\ngc6543a.jpg'));
Please help me use the correct syntax to include the full path, eg. 'C:\Dir1\ngc6543a.jpg'.
I do not believe it is feasible to keep adding the image 'path' to the system addpath function for such high volumes.
Also... if anyone could please post a link to the Image(which)) syntax. I cannot find it.
1 Comment
"Please help me use the correct syntax to include the full path, eg. 'C:\Dir1\ngc6543a.jpg'."
img1 = Image('C:\Dir1\ngc6543a.jpg'); % get rid of WHICH()
Answers (1)
Image Analyst
on 25 Nov 2022
I don't know what "Image" is. Is that your own function or a special function for the Report Generator? It's not the built-in image function because MATLAB is case sensitive.
And what's the point of using which()?
Since you already seem to have the filenames in a cell array or table because you read them in from Excel, why not simply use the index of the one you want?
[numbers, fileNames, raw] = xlsread(workbookName);
img1 = Image(fileNames{3}); % Use filename #3.
12 Comments
Matt O'Brien
on 25 Nov 2022
Edited: Matt O'Brien
on 25 Nov 2022
Image Analyst
on 25 Nov 2022
Image seems to be a function you get when you do the "import" commands. But I can't find any documentation for it. Evidently they're calling which() to get the full path and name of the image file. They're assuming it's on the search path somewhere but that you just want to pass in the base file name for some reason. I believe you could pass in the full filename directly if you have it, just like I showed you already. Does that not work? Did you look over all files and use isfile to see if the file actually exists before you try to use it? If you still have trouble, attach your workbook, or filenames variable in a .mat file, so I can check it out.
Matt O'Brien
on 25 Nov 2022
Image Analyst
on 25 Nov 2022
I'm in Eastern US time zone. I'm surprised the full path name as a character array does not work since that is exactly what which() returns. Where is the documentation on Image (with a capital I not a lower case i)? I can't find it.
Matt O'Brien
on 25 Nov 2022
Moved: Stephen23
on 25 Nov 2022
Matt O'Brien
on 25 Nov 2022
Matt O'Brien
on 25 Nov 2022
Moved: Stephen23
on 25 Nov 2022
"I get this error message."
Why are you calling WHICH with a full path? The entire point of WHICH is to return the path of something that:
- is not a full path, and
- is on the MATLAB search path (the WHICH documentation makes this very clear: "If item is a file name including the extension, and it is in the current working folder or on the MATLAB path, then which displays the full path of item.")
If you already have the full path of something that is not on the MATLAB search path, then WHICH does absolutely nothing for you. Image Analyst pointed this out six hours ago, so it is unclear why you are still calling WHICH.
Get rid of WHICH.
"I can only assume Image and which() are functions available via the Report Generator extensions / object model."
Rather than assuming, finding the Image documentation took me ... eight seconds: I clicked on the link you posted, then clicked on "Functions" at the top of the page, then "Images, Figures, Axes..." in the Category browser, and then finally on "mlreportgen.dom.Image". There is no restriction on the image needing to be on the search path.
WHICH is a base MATLAB function, completely unrelated to Report Generator:
Matt O'Brien
on 25 Nov 2022
Matt O'Brien
on 25 Nov 2022
Matt O'Brien
on 25 Nov 2022
"I cannot find any documentation for Which. I cannot find any documentation for Image."
I gave links to both of those in my previous comment, and I also explained the exact three clicks you need to find the Image documentation from the page you already were looking at. But here they are again:
I am sure that after three days reading about this topic you have already read the entire Report Generator documentation twice over, but perhaps someone else might find these screenshots useful:



"If anyone can point me to the Documentation for 'Which' and 'Image' I would really appreciate it."
Tip: practice using the documentation. Always look at what is displayed in the browser (LHS) and at the very top and bottom of every page. There is a lot of hyperlinking and a lot of information, so you have to keep your eyes open.
Categories
Find more on Scripts 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!