How can I set specific Elements of a Matrix to zero without a for loop
Ältere Kommentare anzeigen
Here is my problem:
o= ones(3,3) % Given Matrix
o =
1 1 1
1 1 1
1 1 1
i = [1 2 2]; % column index of o, which should be set to zero
% quantity of rows in o is always exactly the same like length(i)
The result after manipulating matrix o depending on i should be:
o =
0 1 1
1 0 1
1 0 1
My simple solution
for k=1:length(i)
o(k,i(k))=0;
end
How can i do that without a for loop. In fact, the number of rows of matrix o is 10 000.
Thank you very much!
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!