Creating a vector of stock symbols
1 次查看(过去 30 天)
显示 更早的评论
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)')
0 个评论
采纳的回答
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
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!