creating matrix of 1 nd -1

how can i generate random matrix of 1 and -1 ...
thanks in advance

2 件のコメント

Thomas
Thomas 2012 年 3 月 21 日
Do you want the elements of the matrix to be only 1 and -1 or between 1 and -1
umar siyab
umar siyab 2012 年 3 月 21 日
i want my matrix to be 1 and -1 and it should be 256 by 256 ... basically i want a pesudo random bit generator which can generate a matrix of 1 and -1

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

回答 (2 件)

Jan
Jan 2012 年 3 月 21 日

1 投票

1 and -1:
x = 1 - (rand(3,5) > 0.5) *2;
From -1 to 1:
x = 1 - rand(3,5) *2;

1 件のコメント

umar siyab
umar siyab 2012 年 3 月 21 日
thanks sir
and it really helped me..

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

David Young
David Young 2012 年 3 月 21 日

0 投票

Assuming that you want values of 1 and -1 only, you can do
2*randi(2, m, n) - 3

1 件のコメント

umar siyab
umar siyab 2012 年 3 月 21 日
sorry it is undefined function in matlab i think ....m new to matlab so don'y know much about these fnction

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

カテゴリ

ヘルプ センター および File ExchangeRandom Number Generation についてさらに検索

質問済み:

2012 年 3 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by