problem with manipulation a vector randomly

1 回表示 (過去 30 日間)
Rica
Rica 2012 年 12 月 12 日
hi! i usid bsx function to generate fro a vector a matrix by ading a random number. my problem: this function add to the whole vector a random number, but i want to add or substract to each number of the vector a random number. how could i manipulate this statement to generate the matrix?
MM is aknown vector
M=bsxfun(@plus,MM,10*sign(randn([1 1],27,20)).*rand([1 6],27,20))
thank you
  1 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2012 年 12 月 12 日
Can you explain?

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

回答 (1 件)

José-Luis
José-Luis 2012 年 12 月 12 日
編集済み: José-Luis 2012 年 12 月 12 日
You could still use bsxfun, but instead of creating a vector of random numbers, if I understood correctly, you might need to create a matrix of random numbers to add it to the vector. Say MM is a column vector of size m1 and the random matrix is of size m1 x n1
m = 10;
n = 25;
MM = randi(m,10,1);
M = bsxfun(@plus,MM,randn(m,n));

カテゴリ

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