replace the elements of a matrix
1 回表示 (過去 30 日間)
古いコメントを表示
Hello,
Consider a 100x1 matrix, called A, that contains random values of "0" and "1".
The number of "1" is 25 and the rest 75 are "0".
Also, consider a matrix 25x1, called B, that contains random values.
How can I replace the "1" of matrix A with the values of matrix B?
The "0" of A would not be influenced.
Thank you.
Best,
Pavlos
0 件のコメント
採用された回答
Azzi Abdelmalek
2014 年 2 月 13 日
A(A==1)=B
2 件のコメント
Azzi Abdelmalek
2014 年 2 月 13 日
This is not true. Look at this example
%exmple
A=zeros(100,1);
A(randperm(100,25))=1
B=rand(25,1)
%----------------------
A(A==1)=B
その他の回答 (1 件)
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!