Trying to use if to create a table

1 回表示 (過去 30 日間)
Emil Petersen
Emil Petersen 2022 年 6 月 5 日
回答済み: Jan 2022 年 6 月 5 日
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 Center および File ExchangeTime Series Objects についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by