Multiple plots within 1 figure

1 次查看(过去 30 天)
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?

采纳的回答

Voss
Voss 2024-7-4

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 个评论
Poulomi
Poulomi 2024-7-4
oh my god!
Thank you so much! I think I was blind when I was trying to figure out what is the problem!

请先登录,再进行评论。

更多回答(0 个)

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by