How to save same input values in output

Hello everyone, I hope you are doing well.
I have the four cells and each cell has four column .
i applied the following algorithm which find the histogram of second column of each cell, and find the unique value and count and repeat the values based on count.
At the output i only get single column in the cell, but i want the the 2nd preprocessed column with all other column which present in the input of each cell. How can i do it in MATLAB
K=4
for i = 1:K
T = C1{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);
val{i}=Values;
cnts{i} = counts;
end
for k =1:K
c = cnts{k};
v = val{k};
z=k+1;
for j=z:K
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)= nan;
cnts{j}(n) = nan;
end
end
cnts{k}(m) = c(m);
end
val{j} = temp;
end
end
fnRM=@(v,c)repmat(v,1,c);
for i=1:numel(val)
ix=isfinite(cnts{i});
C{i}=cell2mat(arrayfun(fnRM,val{i}(ix),cnts{i}(ix),'UniformOutput',false).');
Cluster{i}=C{1,i}.';
end

댓글 수: 5

dpb
dpb 2022년 6월 28일
편집: dpb 2022년 6월 28일
You haven't accepted the answer to the last Q? yet of the code you used above...
In it above, it would be more efficient to write
C{i}=cell2mat(arrayfun(fnRM,val{i}(ix),cnts{i}(ix),'UniformOutput',false).').';
as I showed there instead of creating yet another cell array of the same content.
As for this Q?, it's not at all clear what your expected output should be/look like -- show us a small example input and then the output which that should generate.
ADDENDUM
As noted in the original, I presumed since you defined the count and value arrays as row vectors that's what you'd want for outputs.
If a column vector is what is known to be wanted, then it would be better to redefine the anonymous function to create the column vector there -- then it can, in fact, be catenated...
>> fnRM=@(v,c)repmat(v,c,1);
>> clear C
>> for i=1:numel(Value),ix=isfinite(Counts{i});C{i}=cell2mat(arrayfun(fnRM,Value{i}(ix),Counts{i}(ix),'UniformOutput',false));end
>> C
C =
1×6 cell array
{60×1 double} {86×1 double} {98×1 double} {15×1 double} {12×1 double} {12×1 double}
>>
Stephen john
Stephen john 2022년 6월 29일
@dpb in previous we used only single column, now we have four column, but we are processing single column which is 2nd column of every cell, and we want to use the same values of remaining column as is it in the output.
Stephen john
Stephen john 2022년 6월 29일
@dpb I was offline, i accept the previous answer. But now we have four column in which we are processing second column, and produce the output, but i want the remaining column as same as in the input
dpb
dpb 2022년 6월 29일
Again, don't try to describe, SHOW a small example input and expetced output...it's much faster for us and more likely to result in the actual result described--I really don't follow the above precisely and don't have time to try to puzzle it out.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

릴리스

R2022a

질문:

2022년 6월 28일

댓글:

dpb
2022년 6월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by