Multiple plots within 1 figure

조회 수: 1 (최근 30일)
Poulomi
Poulomi 2024년 7월 3일
댓글: Voss 2024년 7월 4일
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!
Voss
Voss 2024년 7월 4일
You're welcome!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by