If then on column based upon number
1 view (last 30 days)
Show older comments
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 Comments
Walter Roberson
on 9 Jul 2021
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?
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!