How to use find function to get log of the values?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi,
I'm trying to create a new array B where the values are logs of array A (if greater than 1). If the value is smaller or equal to 1 I need to add 39 to these. So far I'm up to here but I don't know how to add that 39
A=[8 14 3;-13 1 42;-39 -8 15];
B=zeros(size(A));
l=find(A>1);
B(1:length(l))=log(A(l));
Thanks in advance
0 commentaires
Réponse acceptée
Akiva Gordon
le 8 Nov 2012
Use logical indexing to accomplish this:
A = [8 14 3; -13 1 42; -39 -8 15];
B = zeros(size(A));
Valid indices are those in which A is greater than 1,
vi = logical(A>1);
Where we found a logical "true", take the log of that location in A,
B( vi) = log(A(vi));
For the other indices, add 39 to them,
B(~vi) = A(~vi)+39;
Is this the output you were expecting?
B =
2.0794 2.6391 1.0986
26.0000 40.0000 3.7377
0 31.0000 2.7081
2 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Multidimensional Arrays dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!