フィルターのクリア

I have a two 2D Arrays with 140 zeros, for the 1st I want 70 numbers to have a value between 0 to 1, for the 2nd I want the remaining 70 to have a value <1 and >0

1 回表示 (過去 30 日間)
Hi everyone,
I currently have the below where N=140 In D1 I want half of the rows (i.e. 70 of them) to have a value >0 but <1, In D2 I want half of the rows (but not the same rows as D1 to have a value >0 and <1
Please can someone help around the best way of doing this?
D1=zeros(N,1); D2=zeros(N,1)

採用された回答

Thorsten
Thorsten 2016 年 1 月 22 日
編集済み: Thorsten 2016 年 1 月 22 日
N = 140;
ind = randperm(N);
D1 = zeros(1,N);
D2 = zeros(1,N);
D1(ind(1:N/2)) = rand(1,N/2);
D2(ind(N/2+1:end)) = rand(1,N/2);
% visualize
stairs(D1)
hold on
stairs(D2, 'r')
Rand generates random numbers in the open interval (0,1), in accordance with your specification >0 and <1.

その他の回答 (1 件)

Om
Om 2016 年 1 月 22 日
Thank you so much!

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by