Need to create one graph with multiple subplots in a for loop.
조회 수: 4 (최근 30일)
이전 댓글 표시
Hello! I am very new to MATLAB and was given this for loop to work with. My problem is that this code generates multiple graphs depending on how many neurons dff represents. Every time I put the subplot function into the code I still generate multiple graphs instead of just one. Any help would be greatly appreciated as a newbee to MATLAB!
M_dff = max(dff, [], 'all') + 0.01;
min_dff = min(dff, [], 'all') - 0.01;
for i=1:size(dff, 1)
fig = figure('pos', [283 602 1292 354]);
findpeaks(dff(i,:), 2, 'MinPeakHeight', threshold(i), 'MinPeakWidth', 2);
hold on
yline(threshold(i), 'r--', 'LineWidth', 4); hold on
title('\DeltaF / F of Cell ', 'FontSize', 14);
xlabel("Seconds"+newline+" ", 'FontSize', 14);
ylabel('\DeltaF / F', 'FontSize', 14);
ylim([min_dff M_dff]);
xlim([0 size(dff, 2)/2]);
pause(1)
% str_saveas = strcat('Cell_', int2str(i));
% saveas(fig, str_saveas, 'png');
%close all
end
댓글 수: 0
채택된 답변
Voss
2023년 7월 18일
Something like this?
% some random data, so the code runs:
dff = rand(3,10);
threshold = [0.2 0.35 0.25];
%
M_dff = max(dff, [], 'all') + 0.01;
min_dff = min(dff, [], 'all') - 0.01;
fig = figure('pos', [283 602 1292 354]);
N = size(dff, 1);
for i=1:N
subplot(1,N,i)
findpeaks(dff(i,:), 2, 'MinPeakHeight', threshold(i), 'MinPeakWidth', 2);
hold on
yline(threshold(i), 'r--', 'LineWidth', 4); hold on
title('\DeltaF / F of Cell ', 'FontSize', 14);
xlabel("Seconds"+newline+" ", 'FontSize', 14);
ylabel('\DeltaF / F', 'FontSize', 14);
ylim([min_dff M_dff]);
xlim([0 size(dff, 2)/2]);
end
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!