change a value in matrix

2 ビュー (過去 30 日間)
NA
NA 2019 年 4 月 2 日
回答済み: Guillaume 2019 年 4 月 2 日
A=[1,0,5,3,0;2,0,6,0,9;0,0,5,3,1];
idx = randperm(size(A,1),1);
[~,col,val]=find(A(idx,:));
changed=val+0.5*rand;
I want to make a new_A according to changed value. if
idx=2, changed=[2.11,6.11,9.11];
new_A should be
new_A=[1,0,5,3,0;2.11,0,6.11,0,9.11;0,0,5,3,1];

採用された回答

Guillaume
Guillaume 2019 年 4 月 2 日
Note that
idx = randi(size(A, 1));
would make more sense than randperm with just one element output. Anyway,
randomrow = randi(size(A, 1)); %better name than idx as well.
A(randomrow, :) = A(randomrow, :) + 0.5 * rand * (A(randomrow, :) ~= 0)

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeWeb Services についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by