If then on column based upon number

조회 수: 1 (최근 30일)
Cody Dulaney
Cody Dulaney 2021년 7월 9일
댓글: Matt J 2021년 7월 12일
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
Walter Roberson
Walter Roberson 2021년 7월 9일
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 2021년 7월 9일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Matt J
Matt J 2021년 7월 9일
편집: Matt J 2021년 7월 9일
Perhaps this is what you want,
mean(B(A>=2 & A<=4))
  댓글 수: 2
Cody Dulaney
Cody Dulaney 2021년 7월 12일
Thank you I'll have to try this today!
Matt J
Matt J 2021년 7월 12일
You're welcome, but if it does what you want, kindly Accept-click the answer.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by