fill ids numbers in the matrix

조회 수: 4 (최근 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 CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by