Mean and Median of Values in a matrix

조회 수: 6(최근 30일)
Kawalpreet Kaur
Kawalpreet Kaur 2022년 5월 14일
댓글: Dyuman Joshi 2022년 5월 18일
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
Dyuman Joshi
Dyuman Joshi 2022년 5월 14일
I'm assuming you want to do seperate matrices for mean and median values? And that you want to use for loops as well?

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

답변(3개)

Dyuman Joshi
Dyuman Joshi 2022년 5월 14일
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
Dyuman Joshi
Dyuman Joshi 2022년 5월 18일
You are welcome. If your problem got solved, please accept my answer!

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


Kawalpreet Kaur
Kawalpreet Kaur 2022년 5월 14일
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 2022년 5월 14일
Take a look at the groupsummary function.
  댓글 수: 1
Kawalpreet Kaur
Kawalpreet Kaur 2022년 5월 14일
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.

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by