How to seprate elements based on value counts In MATLAB

1 visualización (últimos 30 días)
Stephen john
Stephen john el 23 de Jun. de 2022
Comentada: Stephen john el 27 de Jun. de 2022
Hello Everyone, I hope you are doing well.
I have the data in form of cell array shape 1x6 , in which each cell have specfic values.
I have developed an algorithm which can first create histrogram of each cell. and then find counts of each unique values. After that it it compare the each unique value with other cell. if it equal it assign that value to to the cell which have large counts.
But i am facing a problem in alogrithm
  • The output of argument val
  • first one is when i compare the unique value of each cell if it equal i assign it to other cell.but when it assign the 0 is written in it place. as you can see below in cell 4, i have unique value of 5. when it assign to cell 2 , cell 4 have 0 value in it place.
  • The output of argument cnts
  • Second one is The counts does not added . for example the unique value of 5 have 15 count already in cell 2. and 3 counts from cell 4 should be added in cell 2 so the total count is 18. but in my case it does not work.
clc; clear all; close all;
load 'Dataset.mat'
% BindataF=cell(1,8)
for i = 1:6
T = emptyCell{i};
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);
val{i}=Values;
cnts{i} = counts;
end
for k =1:6
c = cnts{k};
v = val{k};
z=k+1;
for j=z:6
temp = val{j};
cnt_temp = cnts{j};
for m = 1: length(v)
for n = 1: length(temp)
if v(m)== temp(n)
c(m)=c(m)+cnt_temp(n);
temp(n)= 0;
cnt_temp(n) = 0;
end
end
end
val{j} = temp;
cnts{j} = cnt_temp;
end
end
  5 comentarios
Rik
Rik el 23 de Jun. de 2022
I have posted it many times before: at most 3 cells with at most 10 values each. You should show the exact input and the exact output.
You have done only the second of three. Why exactly do you think I will try again to understand your post? I don't have any issues with you tagging me, but what is the point of attracting my attention if you are going to ignore me?
This isn't working, because you refuse to give what we ask for. We don't ask that to annoy you, we ask it to understand what you want. We ask it so we can help you find a solution. Feel free to tag me again when you have solved these points. I will unfollow this thread now, so I will not see any responses.
Stephen john
Stephen john el 27 de Jun. de 2022
@dpb The desired results is the count should be added to already present count

Iniciar sesión para comentar.

Respuestas (1)

Karim
Karim el 23 de Jun. de 2022
Editada: Karim el 23 de Jun. de 2022
If i understand it correctly, you want to keep only the unique values from each cell and find the overal "count" of each value?
If so, i tried to adjust the code accordingly
load('Dataset.mat')
numCells = length(emptyCell);
uVal = cell(1,numCells);
uCounts = cell(1,numCells);
for i = 1:numCells
currCell = emptyCell{i};
[uVal{i},~,uLoc] = unique(currCell);
uCounts{i} = accumarray(uLoc, 1);
for j = 1:i-1
[iLoc,jLoc] = ismember(uVal{i},uVal{j});
if any(iLoc)
% add the counts
uCounts{j}(logical(jLoc)) = uCounts{i}(iLoc);
% remove the value
uVal{i}(iLoc) = [];
uCounts{i}(iLoc) = [];
end
end
end
for some reason i cannot add "Dataset.mat", because i reach my daily upload limit... we are only allowed to upload 10 attachments a day. Hence i cannot run the code n the answer.
Anyhow, here you can see print screens from the result on my pc:

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by