Using Matlab to create a LaTex document (for image import)
37 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Walter Roberson
2022-4-27
编辑:Walter Roberson
2022-4-27
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);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 LaTeX 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!