Filter löschen
Filter löschen

Multiple plots within 1 figure

23 Ansichten (letzte 30 Tage)
Poulomi
Poulomi am 3 Jul. 2024 um 23:18
Kommentiert: Voss am 4 Jul. 2024 um 3:16
I want to make multiple plots within 1 figure
I want to make a plot with days (x axis) and time (y axis set to 30 mins) .
Within each day, I want to make a line (corresponding to when trial was made; new_endpoint) and colour (timepertrial_backtrace).
I want to do this for all the days in that plot but I am not sure how to proceed.
I have put the snippet of code for doing it but it runs for 1 day only.
Any insight will be useful
%%
figure % make new figure
tiledlayout(numel(num_days), 1, 'TileSpacing', 'compact', 'Padding', 'compact');
range_col = 800; % range upper limit for my values
for day = 1:numel(num_days)
% Load the variable for the specific day here
load( fullfile(matlist(days_F3187(1,day)).folder, matlist(days_F3187(1,day)).name) ); % Load variables from the .mat file
% the above are .mat file where i store information for each day and I
% load them 1 by 1 as needed
nexttile;
new_endpoint = endpoint / 12000; % 200 Hz frame rate
trial_color_range = parula(range_col+1); % Generating a color range from 0 to range
for i = 1:trialno
% Map the color based on timepertrial_backtrace within the color range
color_index = min(max(round(timepertrial_backtraced(i)), 0), range_col);
trial_color = trial_color_range(color_index + 1, :); % Select color from the color range
% Plotting the line for the current trial with the assigned color
plot([day-1, day], [new_endpoint(i), new_endpoint(i)], 'Color', trial_color, 'LineWidth', 1);
hold on;
end
hold off;
title(['Day ' num2str(day)]);
xlabel('Day');
ylabel('30 mins');
clear trial_color % Clear the trial_color variable for the next iteration
end
sgtitle('Timepoints within 30-minute sessions colored based on timepertrial\_backtraced');
This is the figure generated:
However, only 1 day is created and I want information for all the days to be displayed.
How should I approach this problem?

Akzeptierte Antwort

Voss
Voss am 4 Jul. 2024 um 1:43

Try replacing numel(num_days) with num_days, i.e.:

figure % make new figure
tiledlayout(num_days, 1, 'TileSpacing','compact', 'Padding', 'compact');
range_col = 800; % range upper limit for my values
for day = 1:num_days
     % your code
end
  2 Kommentare
Poulomi
Poulomi am 4 Jul. 2024 um 2:27
oh my god!
Thank you so much! I think I was blind when I was trying to figure out what is the problem!
Voss
Voss am 4 Jul. 2024 um 3:16
You're welcome!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

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

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by