matlab'for'循环不执行最后一步或单步

时间:2014-02-10 15:57:42

标签: matlab for-loop cycle

我不明白为什么for循环不执行最后一个循环,即字段'PX_TO_BOOK_RATIO'。

javaaddpath('C:\DocumentsandSettings\cascari\Desktop\API\APIv3\JavaAPI\v3.7.1.1\lib\blpapi3.jar')
connection = blp;
FileName='ScopeEconomies';
list={'OPM LN Equity';'FCTY US Equity';'FCCY US Equity'}
bbgfields={'TOT_LOAN_TO_TOT_ASSET'; 'PX_TO_BOOK_RATIO' };
nfields=length(bbgfields);

for i=1:nfields

      [data,sec] = history(connection, list, bbgfields(i), '01/01/1993', '12/31/2013',...
                  {'quarterly','all_calendar_days','nil_value'},'USD');

      temp=[data{:,:}]; 
      eval([char(bbgfields(i)) '=temp']);

      name=char(bbgfields(i));

      xlswrite(FileName, temp, name, 'B1');

end;

当我在bbgfields中只留下一个元素时,我得到了

Attempted to access j(1); index out of bounds because numel(j)=0.
Error in blp/history>eventHandler (line 417)
    outInd(i) = j(1);
Error in blp/history (line 245)
  [d,sec] = eventHandler(b,s,f); 

1 个答案:

答案 0 :(得分:0)

我猜这是因为你正在使用一个细胞作为历史的输入。您是否尝试将其转换为char,如下所示?

[data,sec] = history(connection, list, char(bbgfields(i)), '01/01/1993', '12/31/2013',...
              {'quarterly','all_calendar_days','nil_value'},'USD');