Insert Mathlab figure in Latex
1 回表示 (過去 30 日間)
古いコメントを表示
Telema Harry
2021 年 12 月 16 日
コメント済み: Telema Harry
2021 年 12 月 16 日
Hi,
I have been unable to insert Matlab figure in my LaTex document and I am not sure what the problem is.
I usually use the code below to create the document in MATLAB.
print -depsc Nocostfunction41.eps
\begin {figure}[H]
\centering
\includegraphics[scale =0.4]{Simulation Figures/Nocostfunction41}\\
\caption{Figure 1}
\label{figure1}
\end{figure}
I have attached a screenshot of the error. I am using BigSur OS and TexShop, MATLAB R2021
Has anyone experience this type of problem
0 件のコメント
採用された回答
Alberto Cuadra Lara
2021 年 12 月 16 日
Hello Telema,
It appears that the Latex compiler you are using could not find the file. Usually empty spaces give errors. Try renaming the folder and let's see.
By the way, I wrote a simple script for a colleague a few weeks ago to print custom graphics, save them, etc. It might be helpful.
I have changed the default save format to eps to match your case.
Best,
Alberto.
function myplot(x, y, varargin)
% Function that plot two given datasets x, y with same dimensions
% Examples:
% myplot(x, y)
% myplot(x, y, 'xlabel', '$\phi$')
% myplot(x, y, 'xlabel', '$\phi$', 'grid', 'on')
% Author: Alberto Cuadra
% Last update: 16 Dec 2021
% Inputs (optional)
xlabelname = [];
ylabelname = [];
customfilename = 'myfigure';
customfolderpath = [];
% Constants
Ncolors = length(x);
config = default_config;
% Colormap
colorbw = brewermap(Ncolors, 'Spectral');
% Check varargin inputs (Write custom definitions in case you want to
% have a more generalized routine)
% The input will be, e.g., myplot(x, y, 'xlabelname', xlabelname)
if nargin - 2 > 0
for i = 1:2:nargin-2
switch lower(varargin{i})
case {'xlabelname', 'xlabel'}
xlabelname = varargin{i + 1};
case {'ylabelname', 'ylabel'}
ylabelname = varargin{i + 1};
case {'filename', 'customfilename'}
customfilename = varargin{i + 1};
case 'grid'
config.grid = varargin{i + 1};
case 'saveformat'
config.saveformat = varargin{i + 1};
% Custom stuff ...
end
end
end
% Set up figure
[fig, axes] = generate_figure(config);
xlabel(axes, xlabelname, 'FontSize', config.fontsize, 'interpreter', 'latex');
ylabel(axes, ylabelname, 'FontSize', config.fontsize, 'interpreter', 'latex');
% Plot
for i=1:Ncolors
plot(x(i, :), y(i, :), 'color', colorbw(i, :), 'LineWidth', config.linewidth);
end
% Save figure
folderpath = strcat(pwd, customfolderpath, '\');
filename = customfilename;
saveas(fig, strcat(folderpath, filename), 'epsc');
end
% SUB-PASS FUNCTIONS
function [fig, axes] = generate_figure(config)
% Function to generate a predefined figure
fig = figure;
set(fig,'units','normalized','innerposition',[0.05 0.05 0.9 0.9],...
'outerposition',[0.05 0.05 0.9 0.9]);
axes = gca;
set(axes,'LineWidth', config.linewidth, 'FontSize', config.fontsize-2, 'BoxStyle', config.boxstyle)
grid(axes, config.grid); box(axes, config.box); hold(axes, config.hold); axes.Layer = config.layer;
end
function config = default_config
% Set default configuration parameters
config.fontsize = 22;
config.linewidth = 2;
config.grid = 'off';
config.box = 'off';
config.hold = 'on';
config.layer = 'Top';
config.boxstyle = 'full';
config.saveformat = 'epsc';
end
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!