Trying to use if to create a table

1 次查看(过去 30 天)
I have to do this tick test which is classified as:
I have no problem with classifying uptick, downtick and zero tick. But find it quite hard to classify zero-downtick and zero-uptick. I have tried following:
Rows=height(data);
Uptick=sum(data.price(1:end-1)<data.price(2:end));
downtick=sum(data.price(1:end-1)>data.price(2:end));
Zerotick=sum(data.price(1:end-1)==data.price(2:end));
if data.price(1:end-1)<data.price(2:end)
ZeroUptick=sum(data.price(2:end-1)==data.price(3:end))
end
if data.price(1:end-1)>data.price(2:end)
ZeroDowntick=sum(data.price(2:end-1)==data.price(3:end))
end
PrcUptick=Uptick./Rows*100;
PrcDowntick=downtick./Rows*100;
PrcZerotick=Zerotick./Rows*100;
PrcZeroUptick=ZeroUptick./Rows*100;
PrcZeroDowntick=ZeroDowntick./Rows*100;
Isn't it possible to use the if funtion to create this data? Any help to solve this would be very helpfull..
Kind Regard, Emil Petersen.

回答(1 个)

Jan
Jan 2022-6-5
Remember, that the if condition must be a scalar. You provide a comparison of two vectors:
if data.price(1:end-1)<data.price(2:end)
Then Matlab executes this internally:
if all(data.price(1:end-1) < data.price(2:end)) && ...
~isempty(data.price(1:end-1) < data.price(2:end))
I assume you want something else.
Either use logical indexing. Or create a loop over all "trades" like:
for iTrade = 1:numel(data.price) - 1
if data.price(iTrade) < data.price(iTrade + 1)
...
end
end

类别

Help CenterFile Exchange 中查找有关 Time Series Objects 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by