Simple logical statement

5 views (last 30 days)
Julia
Julia on 18 Jun 2011
Hi I have a question about logical statements.
I have a data set which includes some positive and some negative observations. I need to transform this data set is such a way that all observations that are positive become zero and those that are negative stay the same. What I have is the following:
SP_prices = xlsread('SP500_plusyear.xls', 'b2:b2780');
SP_returns = log(SP_prices(2:end)) - log(SP_prices(1:end-1));
SP_returns_extra = SP_returns(2527:end);
if (SP_returns_extra > 0)
{then SP_returns_extra = 0}
But this doesn't work, so I was wondering how I can change what I have to make it work. Thanks.

Accepted Answer

Walter Roberson
Walter Roberson on 18 Jun 2011
SP_returns_extra(SP_returns_extra>0) = 0;

More Answers (0)

Community Treasure Hunt

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

Start Hunting!