How to find array elements that meet a condition defined by an index vector?
Afficher commentaires plus anciens
Let A be an n by n matrix of 0's. Let L be an n by 1 matrix of integers, which will be used as an index vector. I want to modify the entries of A based on the following rules:
If L(i)=5 and L(j)=5, then A(i,j)=1;
If L(i)=5 xor L(j)=5 (i.e., exatly one of L(i) and L(j) is 5), then A(i,j)=2;
What is the fastest/simplest code to achieve this? I can use a nested for loop for i and j and modify A(i,j) entry by entry. Is there any built in function that I can use?
2 commentaires
KALYAN ACHARJYA
le 21 Juil 2019
Can you explain the difference between L(i) & L(j)?
Dong Dong
le 21 Juil 2019
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Matrices and Arrays dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!