If then on column based upon number

Hello everyone and I'll preface a thank you for any help I receive:
I have 0 code experience but am attempting to run some data in new lab I'm working in and could really use the help. I am attempting to simply average a set of numbers in a column based upon data from another column in an "if then" sense, I believe. I will attempt to explain below:
Column A; Column B:
0 90
0 45
0 45
0 45
1 55
2 65
3 75
4 80
I wish to average the the #'s in column B based upon the #'s in column A such as once column A reaches 4 it avearges the data up to (and excluding) data in row 1 (i.e. 65, 75, 80)
Sorry if this is a poor explenation - any insight would be greatly appreciated.
Thanks,

2 comentarios

Is it correct that any rows in which column A are <= 1 are to be ignored?
Is it correct that for any rows in whcih column A are > 1, that you want a "cumulative mean" -- so for the 2 entry you would mean(65), for the 3 entry you would mean([65 75]), for the 4 entry you would mean([65 75 80]) ?
If that is the case, then if there were then additional rows that had <= 1, then should the "cumulative mean" reset, or should it keep going as if those rows were not there?
For example, if after your current data there were
1 85
2 90
then should the 1 line be quietly ignored, or should it result in the mean for 2 being mean(90) -- cumulative mean only during the "runs" of values?
Cody Dulaney
Cody Dulaney el 9 de Jul. de 2021
Yes any rows in which column A are <= should be ignored
I don't need a corrected mean, I just want a mean for all of the data 2 through 4 (their may be multiple 2's, 3's, but only a single 4 will show up in column A).
And yes line one should be quietly ignored.
Maybe some more indepth explenation would be better. We have subjects making choices and when they get an incorrect choice their is a reversal (Column A keeps track of how many reversals there are 1, 2, 3, until 4 where the test is terminated). Once the test is terminated, I wish to take the last 3 reversals (all of the 2 data, all of the 3 data and the 4 data while ingoring the 1 data in column A) and average that.
Thanks so much for the help and again sorry for any poor explenation I'm probably giving.

Iniciar sesión para comentar.

 Respuesta aceptada

Matt J
Matt J el 9 de Jul. de 2021
Editada: Matt J el 9 de Jul. de 2021
Perhaps this is what you want,
mean(B(A>=2 & A<=4))

2 comentarios

Cody Dulaney
Cody Dulaney el 12 de Jul. de 2021
Thank you I'll have to try this today!
Matt J
Matt J el 12 de Jul. de 2021
You're welcome, but if it does what you want, kindly Accept-click the answer.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Productos

Versión

R2017b

Etiquetas

Preguntada:

el 9 de Jul. de 2021

Comentada:

el 12 de Jul. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by