Using logical indexing to modify non-negative elements of a matrix
Afficher commentaires plus anciens
I need to pass a matrix of radii to the function areaCircle and have it output a matrix the same size of the input with the respective areas in the entries with non-negative radius and -1 in the entries with negative radius as error signaling.
I am trying this
function area = areaCircle(r)
nim = r < 0 %negative-index matrix
r(nim) = -1 % sets the negative entries of the r matrix to -1
area = zeros(size(r));
area(nim)= pi.*r.*r ;% ? this doesn't work
end
How can I achieve it?
2 commentaires
madhan ravi
le 26 Sep 2020
What does non-begative mean?
Juan Carlos Vega Oliver
le 26 Sep 2020
Modifié(e) : Juan Carlos Vega Oliver
le 26 Sep 2020
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Matrix Indexing 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!