How to replace zero with the values present in array

2 ビュー (過去 30 日間)
Stephen john
Stephen john 2022 年 8 月 26 日
コメント済み: dpb 2022 年 8 月 27 日
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 件のコメント
Stephen john
Stephen john 2022 年 8 月 26 日
@Matt J No, each zero Replace with single value
For examples
DataSet=[100 800 0 900 0 100 0 0];
Then New Dataset is
DataSet=[100 800 800 900 900 100 800 900];
Stephen john
Stephen john 2022 年 8 月 26 日
@Matt J There is second method. We will delete, the 0's values and repeat the array from the start to complete. same size as original
For examples I have 8 entries in the dataset
DataSet=[100 800 0 900 0 100 0 0];
New dataset after deleted 0; we have four entries
DataSet=[100 800 900 100 ];
and at last repeat the matrix to complete 8 entries
DataSet=[100 800 900 100 100 800 900 100];

サインインしてコメントする。

回答 (1 件)

dpb
dpb 2022 年 8 月 26 日
移動済み: Matt J 2022 年 8 月 26 日
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 件のコメント
Stephen john
Stephen john 2022 年 8 月 27 日
@dpb repeat to complete 1000 samples
dpb
dpb 2022 年 8 月 27 日
You're missing the point -- how to calculate that number of repetitions is where the hint and ceil() come into play.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by