How to use find function to create a sceond array?

조회 수: 2 (최근 30일)
Patrick
Patrick 2012년 11월 6일
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
Azzi Abdelmalek
Azzi Abdelmalek 2012년 11월 6일
편집: Azzi Abdelmalek 2012년 11월 6일
it's not clear, how did you get 0.2833
Patrick
Patrick 2012년 11월 6일
add 8

댓글을 달려면 로그인하십시오.

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2012년 11월 6일
편집: Azzi Abdelmalek 2012년 11월 6일
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
Patrick
Patrick 2012년 11월 6일
Thanks, I'll try to go with this but still not sure how to add that 8 when value is less than 1.
Azzi Abdelmalek
Azzi Abdelmalek 2012년 11월 6일
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 ));

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Performance and Memory에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by