averaging selected columns and saving to a new file
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Giru Mishra
am 29 Mai 2018
Kommentiert: Ameer Hamza
am 30 Mai 2018
I have a data file with 1st column - time, 2nd column measurement and third one error. I want to average 1st column, 2nd column and 3rd column corresponding to same time over the whole file and make a new file with such values. Also by same time I mean same number before decimal e.g.
4500.34
4500.25
4500.68
3700.57
3700.45
3700.98
so on....
So in above case, 4500.34 4500.25 4500.68 will be considered with same time and 3700.57 3700.45 3700.98 with same time. Now I want to average 1st,2n,3rd columns of same time and make one new point and so on for all same time.
Please help
2 Kommentare
Stephen23
am 29 Mai 2018
@Giru Mishra: please upload a sample file by clicking the paperclip button.
Akzeptierte Antwort
Ameer Hamza
am 29 Mai 2018
You can try this, here x is the matrix name containing 3 columns
[unique_time, ~, index_unique] = unique(floor(x(:,1)));
measurement_average = accumarray(index_unique, x(:,2), [], @mean);
error_average = accumarray(index_unique, x(:,3), [], @mean);
result = [unique_time measurement_average error_average];
10 Kommentare
Ameer Hamza
am 30 Mai 2018
@Giru You are welcome. Yes, the line posted in the comment will take the average of square values under same time.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!