How to replace zero with the values present in array
2 views (last 30 days)
Show older comments
Hello Everyone, I hope you are doing well. I have an array named as Dataset. I have replace 0 in for those values which has histogram count less than 50 percent of maximum value.
Now in my new array Dataset Has some Values which are equal to 0; I want to replace 0 with the Values already present in the array.
For example the array consists of value
34.9609375000000
37.9882812500000
34.9609375000000
These Values should be in placed of 0's
How can i do it in Matlab
Batchdata=Dataset;
fig=figure; set(fig,'visible','off');
h=histogram(Batchdata,10000);
sumofbins=max(h.Values);
size_MP=round(50/100*sumofbins);
ValueofHistogram= h.Values;
Bindata=h.Data;
Binedges=h.BinEdges;
Binedges(end) = Inf;
deleted_data_idx = false(size(Bindata));
for i=1: length(ValueofHistogram)
if ValueofHistogram(i)<size_MP;
deleted_data_idx(Bindata >= Binedges(i) & Bindata < Binedges(i+1)) = true;
end
end
close(fig);
Dataset(deleted_data_idx,:)=0;
5 Comments
Answers (1)
dpb
on 26 Aug 2022
Moved: Matt J
on 26 Aug 2022
array=[34.9609375000000
37.9882812500000
34.9609375000000];
Dataset(deleted_data_idx,:)=repmat(array,1,size(Dataset,2));
presuming
numel(array) == sum(deleted_data_idx)
10 Comments
dpb
on 27 Aug 2022
You're missing the point -- how to calculate that number of repetitions is where the hint and ceil() come into play.
See Also
Categories
Find more on Matrix Indexing 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!