How to seprate elements based on value counts In MATLAB
조회 수: 1 (최근 30일)
이전 댓글 표시
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
Rik
2022년 6월 23일
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.
답변 (1개)
Karim
2022년 6월 23일
편집: Karim
2022년 6월 23일
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:
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!