Need to create one graph with multiple subplots in a for loop.
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
Voss
am 18 Jul. 2023
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
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!