Creating a vector of stock symbols

1 Ansicht (letzte 30 Tage)
Zack Bayhan
Zack Bayhan am 9 Dez. 2014
Kommentiert: Zack Bayhan am 9 Dez. 2014
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)')

Akzeptierte Antwort

Guillaume
Guillaume am 9 Dez. 2014
[] 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 Kommentar
Zack Bayhan
Zack Bayhan am 9 Dez. 2014
Awesome thanks, I will play around with this to see if I can't get it going here in a bit.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by