Need to create one graph with multiple subplots in a for loop.
3 次查看(过去 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!