fill ids numbers in the matrix

1 次查看(过去 30 天)
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’.
.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by