fill ids numbers in the matrix

1 回表示 (過去 30 日間)
EK
EK 2023 年 4 月 29 日
コメント済み: Star Strider 2023 年 4 月 29 日
Hi,
I am trying to refill excell matrix with trial ids numbers and would like to ask if there are easy way to do it in matlab
I have matrices of 4 columns that log stimuli representation in time (logfile, attached below ). The rows are time and the columns are events. The first column logs stimuli id in time. (No stimulus =0, stimulus : 1 2 3 4 5 or 6) The second column logs the trial stages(1=pre stimulus, 2=stimulus, 3=poststimulus interval); column 4 logs Id of repetition for 6 stimuli.
I need to write in column3 Ids numbers of each trial (pre + stimulus + post) through the length of each trial as in example-logfile (column 3). Files are attached below. For example, first trial in the logfile (column2) is 158 rows (pre + stim +post interval). I need to fill correspondent 158 rows in column 3 with 1 which is ID of the first trial. Next trial with 2 and so on as in an example-logfile (column 3). Could anyone help with this?

採用された回答

Star Strider
Star Strider 2023 年 4 月 29 日
I had to plot ‘example-logfile’ to figure out how it works.
Try this —
TLf = readtable('Logfile.xlsx');
TLf.Var3 = cumsum(diff([0; TLf.Var2])<0)+1
TLf = 4760×4 table
Var1 Var2 Var3 Var4 ____ ____ ____ ____ 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1
TLf(end-9:end,:)
ans = 10×4 table
Var1 Var2 Var3 Var4 ____ ____ ____ ____ 0 3 30 5 0 3 30 5 0 3 30 5 0 3 30 5 0 3 30 5 0 3 30 5 0 3 30 5 0 3 30 5 0 3 30 5 0 3 30 5
EDIT — (29 Apr 2023 at 15:26)
It is straightforward to count the ends of the trials and then add them to get ‘Var3’.
.
  2 件のコメント
EK
EK 2023 年 4 月 29 日
Thanks it works!
Star Strider
Star Strider 2023 年 4 月 29 日
As always, my pleasure!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by