Creating a vector of stock symbols

조회 수: 1 (최근 30일)
Zack Bayhan
Zack Bayhan 2014년 12월 9일
댓글: Zack Bayhan 2014년 12월 9일
Hi everyone I'm attempting to create a vector of stock symbols which I will run through a function to retrieve information about the symbol. When I go to create a vector which I plan to run through the function
symbol=['NLY', 'CSCO', 'RAI'];
it returnes that it's equal to
NLYCSCORAI,
is there a way to make to make it work where the entered symbol in the vector can be used this way? I need it to return 'NLY' to have the function work properly, otherwise there is a breakdown in the program. Also I've found when I do a loop it strips the number of letters specified by the loop instead of treating whats inside of the '...' as a unit.
here is the script if you need the function I can get that as well
symbol=['NLY', 'CSCO', 'RAI'];
[hist_date, hist_high, hist_low, hist_open, hist_close, hist_vol] = get_hist_google_stock_data('symbol');
% Plot Daily Hi vs Low
figure
plot([hist_low,hist_high,log(hist_vol)]);
title('Stock');
xlabel('Days Back');
ylabel('Price');
legend('Blue=Daily High','Green=Daily Low','Red=Log(Volume)')

채택된 답변

Guillaume
Guillaume 2014년 12월 9일
[] on strings (char array) concatenates the strings. To hold several strings of different lengths you have to use a cell array:
symbols = {'NLY', 'CSCO', 'RAI'};
to access your symbols you use the {} operator to index into the cell array instead of the matrix ():
for symbidx = 1:numel(symbols)
symbol = symbols{symbidx}
[hist_date, hist_high, hist_low, hist_open, hist_close, hist_vol] = get_hist_google_stock_data(symbol);
%...
end
  댓글 수: 1
Zack Bayhan
Zack Bayhan 2014년 12월 9일
Awesome thanks, I will play around with this to see if I can't get it going here in a bit.

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

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by