How to use find function to create a sceond array?

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 日
What is the size of A
X is not used
Patrick
Patrick 2012 年 11 月 6 日
A is meant to be X, sorry for the confusion.
Azzi Abdelmalek
Azzi Abdelmalek 2012 年 11 月 6 日
what should be the result in this case?
Patrick
Patrick 2012 年 11 月 6 日
I think it should go along these lines 0.2833 0.9057 0.7458 0.9020 0.8543
Azzi Abdelmalek
Azzi Abdelmalek 2012 年 11 月 6 日
do you mean to add 8 or log(8)
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 日

0 投票

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 件のコメント

Azzi Abdelmalek
Azzi Abdelmalek 2012 年 11 月 6 日
X=[1.92 0.05 -2.43 -0.02 0.85];
Y=zeros(size(X));
lo =find(X>=1);
Y(1:length(lo))=log(X(lo ));
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 件)

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by