Filter löschen
Filter löschen

what is the average i have data like

1 Ansicht (letzte 30 Tage)
AKHILESH KUMAR
AKHILESH KUMAR am 30 Nov. 2016
Kommentiert: AKHILESH KUMAR am 1 Dez. 2016
1 1.2
1 1.3
1 1.5
3 1.4
3 1.6
3 1.8
3 1.9
4 1.2
4 1.7
4 0.9
and i want average like
1 1.333333333
3 1.675
4 1.266666667
  3 Kommentare
Jan
Jan am 30 Nov. 2016
@AKHILESH KUMAR: I've formatted the message for you. Please use the "{} Code" button to avoid the standard block format of text in this forum. Thanks.
AKHILESH KUMAR
AKHILESH KUMAR am 1 Dez. 2016
Thank you; it works perfectly but i need explanation. if i have 3 or more column then.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Mohammad Abouali
Mohammad Abouali am 30 Nov. 2016
% I assume you have your data in a row
x = [1 1.2 1 1.3 1 1.5 3 1.4 3 1.6 3 1.8 3 1.9 4 1.2 4 1.7 4 0.9];
% change it in two column sets of data as in your image:
x = reshape(x,2,[])';
% get average in each group
avg = grpstats(x(:,2),x(:,1),'mean');
% form the output matrix like in your figure:
results = [unique(x(:,1)), avg]
results =
1 1.33333333333333
3 1.675
4 1.26666666666667

Weitere Antworten (0)

Kategorien

Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by