Compute a new vector dependent on two others and a random probability

1 回表示 (過去 30 日間)
Laurie Gerstenberger
Laurie Gerstenberger 2016 年 10 月 14 日
コメント済み: KSSV 2016 年 10 月 14 日
Hi everyone, I have the following problem which I can not figure out by myself. I have two column vectors (x &y: 200x1 each). Each entry is giving me percentages (0.2 0.4 or 0.6). I want to compute two vectors (z,k) based on the old vectors percentages. So if either x or y == 0.2, I want z or k to be 1 in 0.2% of occurences in the old vector and 0 in all the other cases. It does not matter whether z or k = 1.
Here is what I have tried so far:
if matrix(:,1)==0.2|matrix(:,2)==0.2
% matrix(:,5)==1
matrix(:,6)==1
end
Here I only wanted to try to find out the occurences where 0.2 is either in column 1 or 2 and then randomly delete the 1 entrys from column 5 and 6. But this already did not work :(.
Please help me!
  3 件のコメント
Laurie Gerstenberger
Laurie Gerstenberger 2016 年 10 月 14 日
Thanks for your answer.yes, I did.
KSSV
KSSV 2016 年 10 月 14 日
Are you facing a problem to find out where 0.2 is? As the numbers are floating try abs(matrix(:,1) -0.2)<eps where eps is a small number.

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

回答 (1 件)

Massimo Zanetti
Massimo Zanetti 2016 年 10 月 14 日
By doing
x==0.2 | y==0.2
you are testing that ALL theelements of x or y equal 0.2. Is that really what you want?
  2 件のコメント
Laurie Gerstenberger
Laurie Gerstenberger 2016 年 10 月 14 日
true..Thanks! No I want that either one element in a row==0.2
Laurie Gerstenberger
Laurie Gerstenberger 2016 年 10 月 14 日
I solved that now and now I have the position where either on of them is 0.2. Is there any way to write 1 randomly in either vector z or y randonly and only in 20% of the occurences of the positions?

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

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by