erorr with the function

조회 수: 8 (최근 30일)
Maciek
Maciek 2015년 2월 1일
댓글: Maciek 2015년 2월 1일
Hi I'm trying understand why the following notification of an error appears on the command window ">> fillMissingData Index exceeds matrix dimensions.
Error in fillMissingData (line 17) tday=varargin(1);" but I can not . Can Somebody show what is wrong with this function
function my_prices=fillMissingData(prices, varargin)
% my_prices=fillMissingData(prices) fills missing price with previous
% day's price
% my_prices=fillMissingData(prices, tday, cday) fills missing prices with previous day's price including non-trading days
% as specified in cday
if (nargin == 1)
my_prices=prices;
for t=2:size(my_prices, 1)
missData=~isfinite(my_prices(t, :, :));
my_prices(t, missData)=my_prices(t-1, missData);
end
else
% We deal only with 2 dim prices array here.
tday=varargin(1);
cday=varargin(2);
my_prices=NaN*zeros(size(cday, 1), size(prices, 2));
tdayIdx=find(tday==cday(1));
if (~isempty(tdayIdx))
my_prices(1, :)=prices(tdayIdx, :);
end
for t=2:size(my_prices, 1)
tdayIdx=find(tday==cday(t));
if (~isempty(tdayIdx))
my_prices(t, :)=prices(tdayIdx, :);
missData=find(~isfinite(my_prices(t, :)));
my_prices(t, missData)=my_prices(t-1, missData);
else
my_prices(t, :)=my_prices(t-1, :);
end
end
end

답변 (1개)

Matt J
Matt J 2015년 2월 1일
I imagine you meant to do
tday=varargin{1};
cday=varargin{2};
  댓글 수: 1
Maciek
Maciek 2015년 2월 1일
i can not set the breakpoints to understand acting of the function but i can not because of the bug

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by