Using Matlab to create a LaTex document (for image import)
37 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Niklas Kurz
el 27 de Abr. de 2022
Comentada: Niklas Kurz
el 28 de Abr. de 2022
In order to import multiple figures in LaTex from one folder I have found following code:
fileID = fopen('./incl_img_latex.txt', 'w');
files = dir('path');
for file = files'
str = file.name;
fprintf(fileID, '\\begin{figure}[htb!]\n\\centering\n\\setlength{\\fboxsep}{1pt}\n\\setlength{\\fboxrule}{1pt}\n\\fbox{\\includegraphics[width = 0.95\\textwidth]{%s}}\n\\caption{}\\end{figure}\n \n', str);
end
fclose(fileID);
This will create for each file some LaTeX code:
\begin{figure}[htb!]
\centering
\setlength{\fboxsep}{1pt}
\setlength{\fboxrule}{1pt}
\fbox{\includegraphics[width = 0.95\textwidth]{IMG_0252.jpg}}
\end{figure}
\begin{figure}[htb!]
\centering
\setlength{\fboxsep}{1pt}
\setlength{\fboxrule}{1pt}
\fbox{\includegraphics[width = 0.95\textwidth]{IMG_0253.jpg}}
\end{figure}
\begin{figure}[htb!]
\centering
\setlength{\fboxsep}{1pt}
\setlength{\fboxrule}{1pt}
\fbox{\includegraphics[width = 0.95\textwidth]{IMG_0254.jpg}}
\end{figure}
\begin{figure}[htb!]
\centering
\setlength{\fboxsep}{1pt}
\setlength{\fboxrule}{1pt}
\fbox{\includegraphics[width = 0.95\textwidth]{IMG_0255.jpg}}
\end{figure}
Now here comes the tricky thing that I want to implement: For each second file the Latex code should vary:
fprintf(fileID, '\\begin{figure}[htb!]\n\\centering\n\\setlength{\\fboxsep}{1pt}\n\\setlength{\\fboxrule}{1pt}\n\\fbox{\\includegraphics[width = 0.95\\textwidth]{%s}}\n\\caption{}\\end{figure}\n \\clearpage \n \n', str);
So something like that is received:
\begin{figure}[htb!]
\centering
\setlength{\fboxsep}{1pt}
\setlength{\fboxrule}{1pt}
\fbox{\includegraphics[width = 0.95\textwidth]{IMG_0252.jpg}}
\end{figure}
\begin{figure}[htb!]
\centering
\setlength{\fboxsep}{1pt}
\setlength{\fboxrule}{1pt}
\fbox{\includegraphics[width = 0.95\textwidth]{IMG_0253.jpg}}
\end{figure}
\clearpage %this Line is new
\begin{figure}[htb!]
\centering
\setlength{\fboxsep}{1pt}
\setlength{\fboxrule}{1pt}
\fbox{\includegraphics[width = 0.95\textwidth]{IMG_0254.jpg}}
\end{figure}
\begin{figure}[htb!]
\centering
\setlength{\fboxsep}{1pt}
\setlength{\fboxrule}{1pt}
\fbox{\includegraphics[width = 0.95\textwidth]{IMG_0255.jpg}}
\end{figure}
\clearpage %this Line is new
How do I achieve this?
0 comentarios
Respuesta aceptada
Walter Roberson
el 27 de Abr. de 2022
Editada: Walter Roberson
el 27 de Abr. de 2022
fileID = fopen('./incl_img_latex.txt', 'w');
files = dir('path');
files([files.isfolder]) = []; %remove . and .. and any directories
for fileidx = 1 : numel(files)
file = files(fileidx);
str = file.name;
fprintf(fileID, '\\begin{figure}[htb!]\n\\centering\n\\setlength{\\fboxsep}{1pt}\n\\setlength{\\fboxrule}{1pt}\n\\fbox{\\includegraphics[width = 0.95\\textwidth]{%s}}\n\\caption{}\\end{figure}\n \n', str);
if mod(fileidx,2) == 0
fprintf(fileID, '\\clearpage\n');
end
end
fclose(fileID);
Más respuestas (0)
Ver también
Categorías
Más información sobre LaTeX 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!