Mean and Median of Values in a matrix

1 view (last 30 days)
Kawalpreet Kaur
Kawalpreet Kaur on 14 May 2022
Commented: Dyuman Joshi on 18 May 2022
I want to take the mean and median of the mean and median of four columns and then store those values in a separate file to plot the graph later. I have 30,000 rows, with four columns as below: The below is an example of the data points. The first column has a different range of flow rates. I want to take the mean and median of all columns, considering that this average will be based on the set range of 1st column, for example, range 800-900, 900-1000, 1000-11000, and so.
The results will be stored in some other file so that I can make the graph. load.
Data file example below:
Flow Rate Entrance Pressure Exit Pressure Pressure Difference
820 7.52 6.5 1.02
820 7.49 6.55 .94
820 7.51 6.52 0.99
820 7.57 6.58 0.99
820 7.58 6.58 1
819 7.54 6.59 0.95
907 9.27 7.8 1.47
915 9.3 7.78 1.52
918 9.35 7.91 1.44
917 9.46 7.97 1.49
1011 11.2 9.44 1.76
1005 11.38 9.58 1.8
1005 11.32 9.54 1.78
1005 11.39 9.49 1.9
1005 11.32 9.51 1.81
1005 11.26 9.44 1.82
Any help is appreciated.
Thanks
  3 Comments
Kawalpreet Kaur
Kawalpreet Kaur on 14 May 2022
Thanks Dyuman. it worked!
Can you please help me on how to store these values for four columns in the form of a matrix in a separate text or excel? So that I can plot a graph from the output matrix.
Appreciate your help.
Thanks!
Dyuman Joshi
Dyuman Joshi on 14 May 2022
I'm assuming you want to do seperate matrices for mean and median values? And that you want to use for loops as well?

Sign in to comment.

Answers (3)

Dyuman Joshi
Dyuman Joshi on 14 May 2022
I am giving you an example for one variable.
meanvalue=[];
medianvalue=[];
for i=800:100:lastvalue
y=flowrate(flowrate>=i&flowrate<(i+100));
meanvalue=[meanvalue mean(y)];
medianvalue=[medianvalue median(y)];
end
Are the groups in the same range here? i.e 800-900 group in flowrate corresponds to 7-8 group in extrance pressure, 6-7 in exit pressure and 0.9-1 in pressure difference, for all ranges?
If they are not, the output matrix you want (with 4 columns) will not be possible.
  5 Comments
Kawalpreet Kaur
Kawalpreet Kaur on 17 May 2022
Hi Dyuman, Thank you for your help. As you suggested, I did some changes,and got the required output.
Thank you for your help.
Dyuman Joshi
Dyuman Joshi on 18 May 2022
You are welcome. If your problem got solved, please accept my answer!

Sign in to comment.


Kawalpreet Kaur
Kawalpreet Kaur on 14 May 2022
Yes, you are right.
For example,
Mean
818 7.14 6.10 1.04
915 8.15 7.00 1.15
.
.
.
and so on until last range.
Median
818 7.25 6.00 1.025
905 8.05 7.01 1.04
.
.
.
and so on until last range.

Steven Lord
Steven Lord on 14 May 2022
Take a look at the groupsummary function.
  1 Comment
Kawalpreet Kaur
Kawalpreet Kaur on 14 May 2022
Hi Steven,
I checked the groupsummary function. I have no specific function variable. I have a range of numbers in column 1, then, accordingly, the mean and median of the col1, col2, col3, and col4, based on the set range of col1.
I am new to Matlab and have not had enough knowledge. Your help would be much appreciated.
Thank you.

Sign in to comment.

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!