实例程序:(用 deepseek 生成代码:批量保存 figure 图片为 jpg 格式,重命名的代码,保存到桌面)
clear all;%清除所有变量 close all;%关闭所有窗口,主要是画图窗口 clc;%清空命令行窗口 %离散求解区域 width=3; height=3; n=100; %离散的单边节点数 x=linspace(0,width,n); y=linspace(0,height,n); %边界条件,初始化 T=zeros(n); T(1,1:n)=100; T(1:n,n)=200; T(n,1:n)=300; T(1:n,1)=500; %声明收敛条件 interation=0; error=1; tol=1e-6; %迭代求解过程 while error>tol Told=T; for i=2:n-1 for j=2:n-1 T(i,j)=0.25.*(T(i-1,j)+T(i+1,j)+T(i,j-1)+T(i,j+1)); end end interation=interation+1; error=max(max(abs(Told-T))); end %画图展示结果 figure(1) contour(x,y,T,15),colorbar title('2D steady atable Temperature 等值线图'),xlabel('x'),ylabel('y') figure(2) pcolor(x,y,T),colormap("jet"),shading interp,colorbar title('2D steady atable Temperature 云图'),xlabel('x'),ylabel('y') figure(3) surf(T) title('2D steady atable Temperature 云图'),xlabel('x'),ylabel('y'),zlabel('T'),colorbar % 假设你已经创建了一些 figure figures = [figure(1), figure(2), figure(3)]; % 这里假设你有3个figure % 获取 Windows 11 桌面路径 desktopPath = fullfile(getenv('USERPROFILE'), 'Desktop'); % 保存路径 savePath = desktopPath; % 保存到桌面 % 遍历每个 figure 并保存 for i = 1:length(figures) % 设置当前 figure 为活动 figure figure(figures(i)); % 生成文件名 fileName = sprintf('figure_%03d.jpg', i); % 例如: figure_001.jpg, figure_002.jpg, ... % 完整文件路径 fullFilePath = fullfile(savePath, fileName); % 保存 figure 为 JPG 格式 saveas(figures(i), fullFilePath, 'jpg'); % 打印保存信息 fprintf('Saved %s\n', fullFilePath); end
程序结果:
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于