How to compare counts of each histogram

Hello everyone, i hope you are doing well. i have the eight clusters. I want to calculate histogram for each cluster, after calculating histogram, i want to compare the count of each values if the count is greater in one cluster assign the value to other cluster and repeat the process till 8 clusters
How can i do that in MATLAB
I have the following code.
for i = 1:8
T = clusters{i}(:,2);
h1(i)=histogram(T,100000,'BinLimitsMode','manual','BinLimits',[0 3e8]);
end

7 Comments

Explain in much, much more detail what "compare" means to you. What exactly do you want to see or compute? It doesn't make sense to just use max() to set the counts equal to the max counts of any histogram, at least not to me.
@Image Analyst Let me explain in detail. for example i have a value which is 20 in cluster 1 and the same value also exist in other cluster which has count greater then first cluster, i want that value to be in second cluster , and this should be run untill it check the values in all clusters.
Your explanation is still not clear to me. Let's take a smaller problem. Here's code that creates a fixed sample data set with 100 elements. Walk us through exactly what steps you want to follow and what results you want to receive with this data set and let's say 4 clusters.
rng default
x = randi(10, 1, 100);
histogram(x)
One possible guess at what you're trying to do is to partition the data into bins that are as close to equal in size as you can get. If that were the case, I don't think you need histogram or histcounts. Using prctile or sorting the data and taking the elements that are evenly spaced (in the case above with 100 values and 4 bins, use elements [25 50 75] of the sorted data.
figure
s = sort(x);
xline(s([25 50 75]), 'r')
hold on
histogram(x, 'BinEdges', [0 s([25 50 75]), 11])
@Steven Lord @Image Analyst Let say i have four clusters , each cluster has different values in it. we find the histogram of the each cluster . When we find histogram, we have counts of all the values in each cluster. for example one value is 500 in cluster one which have 20 counts. the same value 500 exist in any of the four clusters.we find the 500 values in other clusters and check there count. if if exist in any other cluster and its count is less then 20 for example 10 then we assign this counts to the cluster one which has 20 counts already now total count for 500 in cluster one is 30
Your description does not seem to make sense. If you make a histogram, how can one value in your original data contribute to multiple bins?
If a person is aged 47, they will only contribute to the count of people aged between 45 and 50, not to the count of people aged 50 to 55.
It therefore seems you aren't using the terminology I'm expecting. It looks like Steven Lord and Image Analyst have a similar problem.
Try explaining again, but this time with data (at least a tiny example). Maybe you don't want a histogram at all, but you want to group values. That would make some more sense to me.
@Rik @Image Analyst @Steven Lord Yes you are right, i want the group values if it using histogram it would be good. for example as you say that a person aged is 47 it has count value in one cluster for example 30, in the other cluster the same aged 47 exist and its count value if 10, as you see the count value in first cluster is greater (30) then in the other cluster(10). Now I want to to move the value from other cluster to first cluster which make the total count to 40.
I hope now you are clear
Now i have the cell array of 1x8. I have find the unique value and count for each cell.
Now i want to compare the values of every cell. for example if value 80000 exist in first cell. i want to find the same number in other cells. and it run untill values in all cells are compare with one another
Secondly, if value 8000 exist in other cell, then check it count.if count is less then other count, assign that counts to other cell.
The following code. The Values gives unique values from all cells. and count gives the number of time value exist in cell.
I want to use Both of them to compare values of each cells.
BindataF=cell(1,8)
for i = 1:8
T = clusters{i}(:,2);
h1(i)=histogram(T,100000,'BinLimitsMode','manual','BinLimits',[0 3e8]);
BindataF{i}=h1(i).Data;
T1=BindataF{i}
Values=unique(T1)
counts=histc(T1(:),Values)
end

Sign in to comment.

Answers (1)

As per my understanding, you are unable to find the count value of histograms whose data is present with you.
Values attribute helps us to get bin count in histogram in MATLAB
Following code will help you in getting a cell array having count values of each Histogram:
clusters=num2cell(load('matlab.mat'));
h1= cell(1,8);
for i = 1:8
T = clusters{1,1}.clusters{i,1}(:,2);
z =histogram(T,100000,'BinLimitsMode','manual','BinLimits',[0 3e8]);
disp(z.Values)
h1{i}=z.Values;
end
You may also refer to the following documentation:

7 Comments

@Saksham Gupta Thanks for this, But i want to compare the counts/ values of one cluster with other cluster.
Did you overlook my comment above? Again, define "compare" since taking the max in each bin, as you seem to say, makes little sense.
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
@Image Analyst i have attached my dataset above. Compare means if the value in one cluster has value 20 , while the same value exist in other cluster. The count in first cluster is let say 100 while in other cluster it is 10. Then we assign the value of 10 in other cluster to the first cluster which has more value (100)
In a histogram in MATLAB, you can't have overlapping bins. If the second element of your data is 10 and that element is included in bin number 3, then all the other elements containing 10 in the data (be they element 1, 3, 42, or 1000000) must be in bin number 3. So your "same value exist[sic] in other cluster" can't happen if your "cluster" is a histogram bin.
Start at the beginning. Tell us what your data represents, explain exactly what you do to your data at each step as though we have no idea what you're doing. You may assume we know how to write MATLAB code but you may not assume we know your application.
@Steven Lord No, i dnt want to overlap any bin, i want to get the values using Histogram
And the explanation???
s = load('matlab.mat')
s = struct with fields:
clusters: {8×1 cell}
clusters = s.clusters % a cell array
clusters = 8×1 cell array
{40498×5 double} {10148×5 double} { 408×5 double} {12212×5 double} { 3429×5 double} { 1632×5 double} { 6976×5 double} { 2898×5 double}
for k = 1 : numel(clusters)
subplot(3, 3, k);
histogram(clusters{k});
grid on;
ylabel('Count');
xlabel('Value');
end
What do the 5 columns, and variable number of rows represent?
@Image Analyst The useful features are 2nd third and fourth column, in which we are going to develop an algorithm on each feature. if the 2nd column has the value of 23000 and its count is 500, if this value (23000) exist in 2nd column of any other clusters. and has count less than 500 then we assign the value to that cluster.
Have you understand that

Sign in to comment.

Products

Release

R2021b

Asked:

on 14 Jun 2022

Edited:

on 15 Jun 2022

Community Treasure Hunt

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

Start Hunting!