How to remove the value using Histogram

10 次查看(过去 30 天)
I have the following data, in which my original value is 15 which have count of 7360
I want to remove the remaining values which count less then 33% of orginal values or multiple of the original value
for example in this case I have 30,45 ,60,75 and 90 I want to remove this values. and value of 1 also
How can i do that in MATLAB

回答(1 个)

Star Strider
Star Strider 2023-1-24
I have only a vague idea of what you want to do, especially since the .mat file does not appear to contain the same data as depicted in the posted plot image.
Try this —
LD = load(websave('histogram','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1272595/histogram.mat'))
LD = struct with fields:
ans: [8839×1 double]
v = LD.ans;
Ev = linspace(0, 100, 101)
Ev = 1×101
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
figure
hh = histogram(v, Ev);
Vals = hh.Values;
Edgs = hh.BinEdges;
Retain = (Vals > max(Vals)/3);
Out = Vals(Retain)
Out = 1×2
2896 4568
OutBinsLowerEdge = Edgs(Retain)
OutBinsLowerEdge = 1×2
14 15
If you want to remove the associated data in the original file corresponding to those values, that would be relatively straightforward using logical indexing. Another approach would be to use histcounts, return the 'Bins' output, and index into that.
.
  21 个评论
Med Future
Med Future 2023-1-27
@Star Strider @Image Analyst Same Error with secondata
Can you please solve this
Arrays have incompatible sizes for this operation.
Data=NewData;
h=histogram(Data,10000,"BinMethod","sturges",'BinWidth',1,'BinLimits',[1 10000]);
[N,Edges,Bin] = histcounts(Data,10000,"BinMethod","sturges",'BinWidth',1,'BinLimits',[1 10000]);
Retain = N > max(N)/3; % Retain Values In Bins Greater Than One-Third Of The Meximum Bin Count Value
FindBins = find(Retain)
RetainDataLv = (Bin == FindBins); % Values In 'Bin' Corresponding To 'Retain' Test
SzRD = size(RetainDataLv)
[~,idx] = min(SzRD);
RetainData = Data(any(RetainDataLv,idx))
Star Strider
Star Strider 2023-1-27
You need to force ‘Data’ to be a column vector to work with my code, using the ‘(:)’ operator:
Data=NewData(:);
I decided to do this to make my code compatible with all the data sets, since some are row vectors and some are coliumn vectors.
Try this —
LD = load(websave('secondata','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1275815/secondata.mat'));
Data = LD.NewData(:) % Force Column Vector
Data = 16075×1
100.0000 100.0000 100.0000 100.0000 100.0000 100.0000 100.0000 100.0000 100.0000 100.0000
h=histogram(Data,10000,"BinMethod","sturges",'BinWidth',1,'BinLimits',[1 10000]);
[N,Edges,Bin] = histcounts(Data,10000,"BinMethod","sturges",'BinWidth',1,'BinLimits',[1 10000]);
Retain = N > max(N)/3; % Retain Values In Bins Greater Than One-Third Of The Meximum Bin Count Value
FindBins = find(Retain)
FindBins = 1×5
99 100 150 200 250
RetainDataLv = (Bin == FindBins); % Values In 'Bin' Corresponding To 'Retain' Test
SzRD = size(RetainDataLv);
[~,idx] = min(SzRD);
RetainData = Data(any(RetainDataLv,idx)) % Return Desired Subset OF 'Data'
RetainData = 10289×1
100.0000 100.0000 100.0000 100.0000 100.0000 100.0000 100.0000 100.0000 100.0000 100.0000
That should work with all the data vectors, regardless of whether their initial orientation is as row or column vectors.
.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by