Simple logical statement

5 次查看(过去 30 天)
Julia
Julia 2011-6-18
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.

采纳的回答

Walter Roberson
Walter Roberson 2011-6-18
SP_returns_extra(SP_returns_extra>0) = 0;

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by