How do I initialize matrix values from an array of indices?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Joel Stave
il 28 Lug 2016
Commentato: Joel Stave
il 28 Lug 2016
The following code:
idx = 1:10:100;
img(idx,idx) = 1;
...yields an array with 100 '1' values in it. The result I'm looking for is an array with a value of 1 only at (1,1), (11,11) ... (91,91). The only way I can find to get the result I want is:
for i=1:length(idx)
img(i,i) = 1;
end
Is there some way to do this without the 'for' loop, since they tend to be less efficient? Thanks.
0 Commenti
Risposta accettata
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!