How to save image without rendering it?

2 visualizaciones (últimos 30 días)
诗弘
诗弘 el 16 de Abr. de 2025
Respondida: NVSL el 23 de Abr. de 2025
I was running a matlab code aiming to output a spectrum picture on the Supercomputer node. Maybe because it don't contain a GUI, the picture keeps posting me warnings and the output isn't right. I am pretty sure the code is right because I tested it on my PC and it's totally fine. but on supercomputer it can't output the lines drawed by surf(), the title, and the colorbar.
warning message:
Warning: An error occurred while drawing the scene: An error occurred while
rendering after the depth sort.
> In defaulterrorcallback (line 12)
In matlab.graphics.internal/mlprintjob/setPaintDisabled
In alternatePrintPath
In alternatePrintPath
In onCleanup/delete (line 25)
In alternatePrintPath
In print (line 90)
In saveas (line 181)
In process_all_files (line 33)
Warning: An error occurred while drawing the scene: Unidentified trouble during
rendering
> In defaulterrorcallback (line 12)
In matlab.graphics.internal/mlprintjob/setPaintDisabled
In alternatePrintPath
In alternatePrintPath
In onCleanup/delete (line 25)
In alternatePrintPath
In print (line 90)
In saveas (line 181)
In process_all_files (line 33)
wrong output picture:
figure code:
%% 绘图
time_axis = (pace:pace:loop * pace); % 计算每一帧的真实时间
[X, Y] = meshgrid(xaxis, time_axis); % 创建网格,Y 轴为真实时间
switch style
case 'surf'
% 使用 surf 绘制更平滑的频谱图
fig = figure('Visible', 'off'); % 创建不可见的图形窗口
surf(X, Y, spectrum, 'EdgeColor', 'none'); % 使用 surf 绘制
view(2); % 从顶部视角查看
colorbar;
case 'mesh'
fig = figure('Visible', 'off'); % 创建不可见的图形窗口
mesh(X, Y, spectrum);
case 'waterfall'
% 绘制频谱瀑布图
fig = figure('Visible', 'off'); % 创建不可见的图形窗口
waterfall(X, Y, spectrum); % 使用 waterfall 绘制瀑布图
view(2);
colorbar;
zlabel('Amplitude (dB)');
grid on;
otherwise
error('Invalid picture style.');
end
title(['Spectrum Result of ', timestamp]);
xlabel(sprintf('Frequency (Hz)\nSample rate: %.2f Hz, Time: %.2f s', fs, time));
ylabel('Time (s)'); % Y 轴标注为真实时间
the code is a part in a function which returns fig variable, and the main program catches the fig variable and use saveas() to save it as .svg file.
saveas code:
returnfig=processingxx(iq_file, xml_file);
% 保存结果图片为矢量图格式
saveas(returnfig, fullfile(result_dir, append(timestamp, '-0.1s','.svg')), 'svg');

Respuesta aceptada

NVSL
NVSL el 23 de Abr. de 2025
The error “An error occurred while drawing the scene: Unidentified trouble during rendering” generally attributes to the thread that’s driving the graphics card.
You can try the following command that tells MATLAB to stop trying to use the graphics card and use a software version of the OpenGL library.
opengl software
More details can be found at the following MATLAB Answers’ thread.
Hope this heps!

Más respuestas (0)

Categorías

Más información sobre Axis Labels en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by