How to use find function to create a sceond array?
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I'm trying to use find function to create a new array(Y) where the values are natural logarithms of an array (X) if these values are greater than 1. If there are any values remaining in (Y), I need to add 8 to each of the corresponding elements in A.
So far I got this but I'm pretty sure I've got something missing as I dont think I get the right result:
bold
X=[1.92 0.05 -2.43 -0.02 0.85];
Y=zeros(size(X));
log=find(log(X)>=1);
Y(1:length(log))=X(log);*
Any advice would be helpful, thank you.
7 Commenti
Azzi Abdelmalek
il 6 Nov 2012
Modificato: Azzi Abdelmalek
il 6 Nov 2012
it's not clear, how did you get 0.2833
Risposta accettata
Azzi Abdelmalek
il 6 Nov 2012
Modificato: Azzi Abdelmalek
il 6 Nov 2012
Don't use log as a variable, because it's a logarithme function
note that log of a negative number is complex
log(-6)
3 Commenti
Azzi Abdelmalek
il 6 Nov 2012
then use
X=[1.92 0.05 -2.43 -0.02 0.85];
Y=8*ones(size(X));
lo =find(X>=1);
Y(1:length(lo))=log(X(lo ));
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Performance and Memory 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!