if condition is true record value from next row

1 visualización (últimos 30 días)
John Kim
John Kim el 15 de Nov. de 2021
Comentada: dpb el 15 de Nov. de 2021
I am looking to latency of a trial IF the previous row was incorrect "0" and the current row is correct "1" to answer the question to people answer faster if they get the previous question wrong
I have tried using the code below
tabm.Error = tabm.Correct;
%tabm.Error is a new column I am trying to create
if istable (tabm.Error)
[r,c] = size(tabm.Error);
for i=1:r
A = tabm.Correct(r)==0;
B = tabm.Correct(r+1)==1;
if A && B
tabm.Error = 1;
else tabm.Error = 0;
end
end
end
Currently, the Error column is just a copy of the Correct Column
Thank you!
  1 comentario
dpb
dpb el 15 de Nov. de 2021
You didn't subscript the Error variable in the assignment so each assignment writes the whole vector of 1|0.
Excepting your loop over i doesn't use i at all; every refererence to tabm.Correct is to the last and (non-existant) last + one elements. That looks like should have error'ed on an out-of-bounds reference.
Try something more like
ix=[0;diff(tabm.Correct)==1];
tabm.Error=ix;

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by