필터 지우기
필터 지우기

Squeeze array elements with almost (but not exactly) equal value into one element.

조회 수: 2 (최근 30일)
I have the array
A=[1.74500 1.74567 1.73985 1.74271 6.67891 6.662314 6.61031 10.78678 10.76789 ...]
I want to squeeze all the elements 1.7xxxx into one element that is the average of all these elements, then go to the next series 6.6xxxx and reduce them to only one element and so on so that A at the end will look like:
A=[1.7xxxxx 6.6xxxxx 10.7xxxxx ...]

채택된 답변

Walter Roberson
Walter Roberson 2018년 6월 19일
https://www.mathworks.com/help/matlab/ref/discretize.html . Or in older MATLAB you can do much the same thing with the second output of histc()
If you do not have fixed edges then you could use uniquetol()
The idea is that you find grouping numbers based upon the values.
Once you have those, you can use grpstats() from the Statistics Toolbox. Or you can use
[~, ~, bin_numbers] = uniquetol(A);
avg = accumarray(bin_numbers(:), A(:), [], @mean ).'

추가 답변 (1개)

Saeid
Saeid 2018년 6월 19일
Thanks Walter, uniquetol seems to work fine and that's what I was looking for!

Community Treasure Hunt

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

Start Hunting!

Translated by