save multiple plots in user specified folder in jpg form

조회 수: 5 (최근 30일)
Harish M Y
Harish M Y 2021년 9월 6일
댓글: KSSV 2021년 9월 6일
Hi,
I am plotting multiple plots in single code and I want to save all the plots into user specified folder in jog form.
Please help me with this.
The code to generate plots is shown below
figure('Name','Pressure In','NumberTitle','off')
x = out.Pin(:,1);
y = out.Pin(:,2);
plot(x,y);
grid on
title('Pump Inlet Pressure');
xlabel('Time');
ylabel('Pressure');
figure('Name','Pressure Out','NumberTitle','off')
x1 = out.Pout(:,1);
y1 = out.Pout(:,2);
plot(x1,y1);
grid on
title('Pump Outet Pressure');
xlabel('Time');
ylabel('Pressure');
figure('Name','Heat Generation','NumberTitle','off')
hold on
x2 = out.Q2(:,1);
y2 = out.Q2(:,2:end);
plot(x2,y2);
grid on
title('Heat Generation');
xlabel('Time');
ylabel('Heat Flow');
legend('Battery Module 1','Battery Module 2','Battery Module 3','Battery Module 4','Battery Module 5','Battery Module 6','Battery Module 7','Battery Module 8','Battery Module 9','Battery Module 10','Battery Module 11','Battery Module 12','Battery Module 13','Battery Module 14');
figure('Name','Total Heat','NumberTitle','off')
hold on
x3 = out.Q_25_100(:,1);
y3 = out.Q_25_100(:,2);
plot(x3,y3);
grid on
title('Heat Generation');
xlabel('Time');
ylabel('Heat Flow');
legend('Summed Heat Flow');
figure('Name','SOC','NumberTitle','off')
x4 = out.SOC_25_100(:,1);
y4 = out.SOC_25_100(:,2);
plot(x4,y4);
grid on
title('Battery State of Charge');
xlabel('Time');
ylabel('SOC');
legend('SOC');
figure('Name','Battery Temperatures','NumberTitle','off')
hold on
x2 = out.T_25_100(:,1);
y2 = out.T_25_100(:,2:end);
plot(x2,y2);
grid on
title('Battery Module Temperatures');
xlabel('Time');
ylabel('Temperature');
legend('Battery Module 1','Battery Module 2','Battery Module 3','Battery Module 4','Battery Module 5','Battery Module 6','Battery Module 7','Battery Module 8','Battery Module 9','Battery Module 10','Battery Module 11','Battery Module 12','Battery Module 13','Battery Module 14');
figure('Name','Chiller Temperature In','NumberTitle','off')
hold on
x2 = out.Tin_25_100(:,1);
y2 = out.Tin_25_100(:,2:end);
plot(x2,y2);
grid on
title('Chiller Inlet Temperature');
xlabel('Time');
ylabel('Temperature');
legend('Temperature');
figure('Name','Chiller Temprature Out','NumberTitle','off')
hold on
x2 = out.Tout_25_100(:,1);
y2 = out.Tout_25_100(:,2:end);
plot(x2,y2);
grid on
title('Chiller Outlet Temperature');
xlabel('Time');
ylabel('Temperature');
legend('Temperature');

답변 (1개)

KSSV
KSSV 2021년 9월 6일
Read about saveas. After the plot you can use:
saveas(gcf,'Figure1.jpg')
  댓글 수: 2
Harish M Y
Harish M Y 2021년 9월 6일
Thanks, this works for one figure.
I want all the figures to be converted into jpg format and save in user specified folder using uigetdir() with the figure names i mentioned in the code automatically.
KSSV
KSSV 2021년 9월 6일
If you are plotting in a figure:
for i = 1:10
% plot here
imagename = [num2str(i),'.png'] ;
saveas(gcf,imageName)
end

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Sources에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by