优化代码 figure(5) for j=1:length(B5.V_M_CH) %充电时电池端电压 plot(1:length(cell2mat(B5.V_M_CH(j))),cell2mat(B5.V_M_CH(j))); hold on grid on end figure(6) for j=1:length(B5.V_M_DCH) %放电时电池端电压 plot(1:length(cell2mat(B5.V_M_DCH(j))),cell2mat(B5.V_M_DCH(j))); hold on grid on end figure(7) for j=1:length(B5.V_CH_CH) %充电时在充电器上测得的电压 plot(1:length(cell2mat(B5.V_CH_CH(j))),cell2mat(B5.V_CH_CH(j))); hold on grid on end figure(8) for j=1:length(B5.V_CH_DCH) %放电时 负载时测得的电压 plot(1:length(cell2mat(B5.V_CH_DCH(j))),cell2mat(B5.V_CH_DCH(j))); hold on grid on end
时间: 2024-03-05 19:48:53 浏览: 74
plot-number-train.rar_plot data_site:www.pudn.com_train_标号 matla
可以通过使用subplot函数将这些图形合并到一个窗口中,并且不需要重复的代码。代码如下:
```
figure(1)
subplot(2,2,1)
for j=1:length(B5.V_M_CH) %充电时电池端电压
plot(1:length(cell2mat(B5.V_M_CH(j))),cell2mat(B5.V_M_CH(j)));
hold on
grid on
end
title('充电时电池端电压')
subplot(2,2,2)
for j=1:length(B5.V_M_DCH) %放电时电池端电压
plot(1:length(cell2mat(B5.V_M_DCH(j))),cell2mat(B5.V_M_DCH(j)));
hold on
grid on
end
title('放电时电池端电压')
subplot(2,2,3)
for j=1:length(B5.V_CH_CH) %充电时在充电器上测得的电压
plot(1:length(cell2mat(B5.V_CH_CH(j))),cell2mat(B5.V_CH_CH(j)));
hold on
grid on
end
title('充电时在充电器上测得的电压')
subplot(2,2,4)
for j=1:length(B5.V_CH_DCH) %放电时 负载时测得的电压
plot(1:length(cell2mat(B5.V_CH_DCH(j))),cell2mat(B5.V_CH_DCH(j)));
hold on
grid on
end
title('放电时负载时测得的电压')
```
这段代码将四个图像合并到一个窗口中,并且使用subplot函数将它们分成四个等大小的部分。每个子图都有一个不同的标题,可以更好地展示数据。
阅读全文