one multiplot figure instead of many partially filled figures
37 ビュー (過去 30 日間)
古いコメントを表示
Hello,
How to correct my code to obtain one multiplot figure instead of many partially filled multiplot figures??
heart_rate = {'30', '40', '45', '60', '80', '90', '100', '120', '140', '160', '180', '200', '220',...
'240', '260', '280', '300'}
figure;
tiledlayout(2, 4, TileIndexing='columnmajor')
for kleads = 1:length(ECGLeads)
nexttile
sample_snr{kleads} = snr_ecg_leads(:, kleads)
sample_heart_rate = str2double(heart_rate)
plot(sample_heart_rate, snr_ecg_leads(:, kleads));
xlabel('Heart Rate (bpm)');
ylabel('SNR (dB)');
title([Leads(kleads)]);
output_fig_heart = [path_data_fig_heart_rates, Leads{kleads},'.fig']
output_fig_heart_jpg = [path_data_fig_heart_rates, Leads{kleads},'.jpg']
saveas(gcf, output_fig_heart, 'fig')
saveas(gcf, output_fig_heart_jpg, 'jpg')
%grid on;
end %kleads
0 件のコメント
回答 (1 件)
Madheswaran
約17時間 前
編集済み: Madheswaran
約17時間 前
Hi @Elzbieta
The behavior you are facing is because you are saving figure (using 'saveas') inside the loop. Each 'saveas' call is saving the entire figure while it's still being populated. This results in multiple partial figures being saved, rather than one complete figure.
To solve this problem, you need to move all the 'saveas' commands outside the plotting loop after all subplots are created.
% ... Existing code
figure;
tiledlayout(2, 4, 'TileIndexing', 'columnmajor')
for kleads = 1:length(ECGLeads)
nexttile
sample_snr{kleads} = snr_ecg_leads(:, kleads);
sample_heart_rate = str2double(heart_rate);
plot(sample_heart_rate, snr_ecg_leads(:, kleads));
xlabel('Heart Rate (bpm)');
ylabel('SNR (dB)');
title(Leads{kleads});
end
% Then save the complete figure after all subplots are done
output_fig_heart = [path_data_fig_heart_rates, 'multiplot.fig'];
output_fig_heart_jpg = [path_data_fig_heart_rates, 'multiplot.jpg'];
saveas(gcf, output_fig_heart, 'fig');
saveas(gcf, output_fig_heart_jpg, 'jpg');
The above code would produce a single image with all subplots properly arranged in a tiled layout instead of multiple partial figures.
Hope this helps!
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Printing and Saving についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!