How to embed images with variable root folders to HTML reports?
    18 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Ben
 el 2 de Mzo. de 2023
  
    
    
    
    
    Respondida: Ben
 el 10 de Mzo. de 2023
            Hi MATLAB community,
I've got a script producing a html report with text and images. The images have been created in MATLAB (as figures), and have been exported as .png files before being read into the report with the following code:
fprintf(fidHTML, '%s\r\n', ['<img src="Figures/JointProbabilities.png','" alt="HTML5 Icon">']);
Where 'fidHTML' is the report. This worked when the path to the images in consistent.
However, now I have changed the code so that the images are saved in a folder dependent on variable names, so the path to the images depends on the variable names and the specific run. The path to the images now is as follows:
Filepath = [outputDir,'/','Summary_Figures/',inputFile.name,'/',saveName,'/JointProbabilities.png']
I have tried a few ways but incorporate these variable names and the new path into the "<img src = ...." line of code above but haven't been able to figure it out. Can you use variable names like this when adding images to html reports? If not, what is an alternative?
As an example, I don't understand why something like:
fprintf(fidHTML, '%s\r\n', ['<img src="Filepath','" alt="HTML5 Icon">']);
Doesn't work, or why this functionality doesn't exist?
Any suggestions appreciated!
Thanks :)
0 comentarios
Respuesta aceptada
  Suman Sahu
    
 el 10 de Mzo. de 2023
        
      Editada: Suman Sahu
    
 el 10 de Mzo. de 2023
  
      Hi Ben, 
The reason why the line of code you provided doesn't work is because you are passing the string "Filepath" instead of the Filepath variable's actual value.
Here is an example of code that shows how you can achieve that: 
%create the full path to the image file
filepath = fullfile(outputDir, 'Summary_Figures', inputFile.name, saveName, 'JointProbabilities.png'); 
%pass the path as placeholder 
fprintf(fidHTML, '<img src="%s" alt="HTML5 Icon">\n', filepath); 
You can read more about the fullfile function from here: Build full file name from parts - MATLAB fullfile - MathWorks 
Hope it helps. 
Más respuestas (1)
Ver también
Categorías
				Más información sobre Environment and Settings en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

