fill ids numbers in the matrix

1 view (last 30 days)
EK
EK on 29 Apr 2023
Commented: Star Strider on 29 Apr 2023
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?

Accepted Answer

Star Strider
Star Strider on 29 Apr 2023
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’.
.

More Answers (0)

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!