フィルターのクリア

Change random values in the matrix of 234*10000

1 回表示 (過去 30 日間)
Harsh Rob
Harsh Rob 2020 年 2 月 7 日
コメント済み: Harsh Rob 2020 年 2 月 7 日
I have a matrix of 10*10 (in this example, actually the matrix is 234*10000) and I have to change the values at random locations.
I tried using the randperm function but it is able to change the values only in the beginning locations. Could someone advise on this please
X= rand(10)
shi=randperm(10,3); %For 10000 simulations and limiting the jump to go only upto 1673
Initial_X = X(shi);
X(shi) = randperm(5,length(shi)); %Change the values at these values of 'i' which is derived from the randperm function above
Final_X = X(shi);

採用された回答

KSSV
KSSV 2020 年 2 月 7 日
You should follow like this:
X= rand(10)
shi=randperm(numel(X),3); %For 10000 simulations and limiting the jump to go only upto 1673
Initial_X = X;
X(shi) = rand(size(shi)); %Change the values at these values of 'i' which is derived from the randperm function above
Final_X = X;
  3 件のコメント
Bhaskar R
Bhaskar R 2020 年 2 月 7 日
X(shi) = randi([your big number limit], size(shi));
Harsh Rob
Harsh Rob 2020 年 2 月 7 日
Thanks KSSV and Bhaskar. It works for me now.

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

その他の回答 (1 件)

Bhaskar R
Bhaskar R 2020 年 2 月 7 日
X= rand(10); % total locations, 10*10 = 100;
loc = randperm(numel(X), 1); % out of 100 locations i pick one random location choosen
X(loc) = rand(1); % assigning random value to randomly picked location
  1 件のコメント
Harsh Rob
Harsh Rob 2020 年 2 月 7 日
No it does not work. I used the same logic. So basically, this new random number introduced should be a higher number so that I can differentiate. Also, I have to make this changes at say 10 random places in the 10*10 matrix with a bit higher values.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by