フィルターのクリア

hi,I am trying to generate a vector with zeros and then replacing 20%,30%,40% of the bits with 40.IS it possible?

2 ビュー (過去 30 日間)
the code vector is v=[0 0 0 0 0 0 0 0 0 0 0 0];
I am trying to generate
v=[0 0 40 0 0 0 40 0 0 0 0]; %%these 40 is random
v=[0 40 0 40 0 0 40 0 0 0];
v=[ 40 0 40 0 0 0 40 0 40 0]
Any kind of suggestion would be appreciated. TIA

採用された回答

Walter Roberson
Walter Roberson 2016 年 7 月 11 日
fill_with = 40;
fillpercent = 30;
fill_length = 12;
fill_mask = rand(1, fill_length) * 100 <= fillpercent;
v = zero(1, fill_length);
v(fill_mask) = fill_with;
  2 件のコメント
nafila aytija
nafila aytija 2016 年 7 月 12 日
thanks a lot for your answer.It works completely fine.But I am trying to do it for a serious of percentage (eg: 30% ,40%,50%) and I do not know how to do it...
Walter Roberson
Walter Roberson 2016 年 7 月 12 日
fillpercents = [30 40 50];
num_percents = length(fillpercents);
v = zeros(num_percents, fill_length);
for K = 1 : num_percents
fill_mask = rand(1, fill_length) * 100 <= fillpercent;
v(K, fill_mask) = fill_with;
end

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by