Info
此问题已关闭。 请重新打开它进行编辑或回答。
How to change elements in several arbitrary positions at the same time
1 次查看(过去 30 天)
显示 更早的评论
Hello, I have a matrix A=[0 0 0 0; 0 0 0 0; 0 0 0 0], which I want to change the value of some elements. I have another matrix B=[1 2; 1 3; 2 4], which shows the position of the elements I want to change in A. For example, for the first row in A, I want to change the 1st and 2nd elements from 0 to 1; for the second row in A, I want to change the 1st and 3rd elements to 1; and so on. The final result I am looking for should be C=[1 1 0 0; 1 0 1 0; 0 1 0 1]. I know I can do it with a loop. But I want faster solution. Please help. Thank you!
0 个评论
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!