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 日

0 投票

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 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

製品

リリース

R2017b

質問済み:

2021 年 7 月 9 日

コメント済み:

2021 年 7 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by