Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
Error for loop trough cell array
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello I have this 1x10 cell array named ticker_list: ('GE' 'BAC' 'VALE' 'AMD' 'PFE' 'F' 'INTC' 'NOK' 'BABA' 'UL') and I have to make the for loop through every cell take the data from yahoo finance and plot. When I run the code below i receive an error and the plotting stops at the sixth security. The error is:
if true
c=yahoo;
for sec = 'ticker_list'
field = 'adj Close';
date_begin = datenum(2012,12,31);
date_end = datenum(2016,12,31);
d = fetch(c,sec,field,date_begin,date_end);
figure('Name','Closing Price');
plot(d(:,1),d(:,2),'LineWidth',2);
datetick;title('Closing price');ylabel('USD');
end
Error using yahoo/fetch (line 387)
Unable to return historical data for given security.
Error in untitled (line 7)
d = fetch(c,sec,field,date_begin,date_end);
댓글 수: 0
답변 (1개)
Guillaume
2017년 2월 24일
" the plotting stops at the sixth security"
for sec = 'ticker_list'
iterates over the characters of the char array 'ticker_list' (so sec is at first 't', then 'i', etc.). The sixth character is '_'. I assume that 't', 'i', etc. can be matched to a ticker, but not '_'. Of course, none of this is what you want. I suspect your code should be
for sec = ticker_list %iterate over the columns of the cell array instead of characters of a string
%...
d = fetch(c, sec{1}, field, date_begin, date_end);
Note: Learn to use the debugger. Had you used it and stepped through your code as it executed, you would have noticed the problem immediately.
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!