Need to create one graph with multiple subplots in a for loop.

3 Ansichten (letzte 30 Tage)
Michael
Michael am 18 Jul. 2023
Kommentiert: Voss am 18 Jul. 2023
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

Akzeptierte Antwort

Voss
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

Weitere Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Produkte


Version

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by