How to save same input values in output
Show older comments
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 Comments
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.
dpb
on 28 Jun 2022
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
on 29 Jun 2022
Stephen john
on 29 Jun 2022
dpb
on 29 Jun 2022
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.
Answers (0)
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!