Random no matrix for 1 & -1
6 ビュー (過去 30 日間)
古いコメントを表示
I want to generate a random matrix for which if element is < 0.5 it is equal to -1 and if >=0.5 its equal to 1 . kindly correct the code.......... I have attached....... Thanks
clc
clear all
format compact
nrows= 5
fm_array = rand(nrows)
if fm_array >= 0.5
fm_array == 1
else
fm_array == -1
fm_array
end
0 件のコメント
採用された回答
Guillaume
2015 年 9 月 4 日
nrowcol = 5;
fm_array = rand(nrowcol);
fm_array(fm_array < 0.5) = -1;
fm_array(fm_array >= 0.5) = 1;
その他の回答 (1 件)
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!