フィルターのクリア

how to create a vector for a stimulus?

2 ビュー (過去 30 日間)
Matheus Brito
Matheus Brito 2021 年 7 月 12 日
回答済み: Walter Roberson 2021 年 7 月 12 日
Hello everyone,
I need help creating a vector based on the stimulus's changing position.
I have a stimulus that moves from the center down and from the center up, randomly every 0.9 seconds (See thinnest line in the image).
This stimulus has an amplitude of 70 centimeters.
How can I create a vector that plots this stimulus?
thanks!

回答 (1 件)

Walter Roberson
Walter Roberson 2021 年 7 月 12 日
A = 70;
p = 0.5;
t = (0:100)*0.9;
y = zeros(size(t));
state = 0;
for K = 2 : numel(t)
R = rand();
if R > p
y(K) = y(K-1);
elseif state == -1 || state == 1
state = 0;
y(K) = 0;
elseif R > p/2
state = -1;
y(K) = -A;
else
state = 1;
y(K) = A;
end
end
stairs(t, y)

カテゴリ

Help Center および File ExchangeAudio and Video Data についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by