Changing a row vector into a logical vector

1 回表示 (過去 30 日間)
Kim
Kim 2015 年 5 月 5 日
コメント済み: Purushottama Rao 2015 年 5 月 5 日
I have row vectors representing the appearance of a stimulus. The stimuli are logged as a square wave such that when the stimulus is present the vector elements change values until it disappears. I also have a time vector with the same number of elements. I would like to change the stimulus vector into a vector of 1s and 0s such that there is a 1 for the time the stimulus is present, and zero otherwise. If possible I'd like to index it to the time vector so that I have the time the stimulus is present. Of course, there may be a better way to achieve the goal. Please help. I've spent so many hours on such a simple problem! Thank you!

回答 (1 件)

Michael Haderlein
Michael Haderlein 2015 年 5 月 5 日
If s is your stimulus array and t your time array and, let's say a value of s larger than 0.5 indicates this stimulus:
s_logical=s>0.5;
s_stimulus_on=s(s_logical);
t_stimulus_on=t(s_logical);
plot(t,s,t_stimulus_on,s_stimulus_on)
  1 件のコメント
Purushottama Rao
Purushottama Rao 2015 年 5 月 5 日
I had the same answer..

サインインしてコメントする。

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by