plotting visual stimulus on timeseries graph?

15 ビュー (過去 30 日間)
nines
nines 2021 年 4 月 12 日
回答済み: Aashray 2025 年 6 月 18 日 7:21
Hello!
I want to plot every stimulus onset as a multiple bars on the x axis on my timseries graph.
What kind of works so far is below:
onset = [100 120 130]
plot(time, timeseries); hold on
stem(ons, ones(1, length(ons)))
Which produces a graph like this:
but i want a graph that plots the onset times + 32 seconds as a line at the top of the graph:
any help would be much appreciated!

回答 (1 件)

Aashray
Aashray 2025 年 6 月 18 日 7:21
Hi @nines,
I understand that you want to mark specific onset times (shifted by 32 seconds) with short horizontal lines at the top of a time-series plot instead of using “stem()”, because it draws vertical lines from the bottom up.
You can simply use “plot()” function to mark small dashes at each of onset location on the top of graph:
% Sample time-series data
time = 0:0.1:600; % Time vector (0 to 600 seconds)
timeseries = 0.5 + 0.4*sin(2*pi*time/150); % Signal
% Onset times in seconds
onset = [100 120 130];
% Offset by 32 seconds
onset_shifted = onset + 32;
% Plot the time-series signal
plot(time, timeseries, 'r'); hold on;
% Get current y-axis limits to position top dashes
yl = ylim;
y_top = yl(2); % Top of the y-axis
y_dash = y_top - 0.02; % Dash height slightly below max
% Length of each dash (in x-units)
dash_len = 1;
% Plot small horizontal dashes at the top
for i = 1:length(onset_shifted)
x = onset_shifted(i);
plot([x - dash_len/2, x + dash_len/2], [y_top y_top], 'b-', 'LineWidth', 10);
end
xlabel('Time (s)');
ylabel('Signal');
title('Time-series with Onset + 32s Markers');
In the above plot, the blue marks are present just below the word "Time" in the title of the plot. You can also increase their width or length to make them more visible.

カテゴリ

Help Center および File ExchangeNeuroimaging についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by