Hello everyone. I am trying to get this code working:
% [num,txt] = xlsread('C:\Program Files\MATLAB\R2012a\StockSymbols.xls')
% or another alternive: Browse file location
[f, p] = uigetfile({'*.xls';'*.xlsx'},'Pick StockSymbols file');
filename=fullfile(p,f);
[num,txt] = xlsread(filename);
% Get stocks
DATE = txt(2:end,1); % Date begins from second row
% Sort data in case dates are not in chronological order
[DATE_num,sortIndex] = sort(datenum(DATE,'mm/dd/yy')); % no hour,minute and second in your date data
BA = num(sortIndex,1);
BAC = num(sortIndex,2);
CAT = num(sortIndex,3);
CSCO = num(sortIndex,4);
DIS = num(sortIndex,5);
GE = num(sortIndex,6);
HD = num(sortIndex,7);
IBM = num(sortIndex,8);
JPM = num(sortIndex,9);
KFT = num(sortIndex,10);
KO = num(sortIndex,11);
MMM = num(sortIndex,12);
MSFT = num(sortIndex,13);
PFE = num(sortIndex,14);
PG = num(sortIndex,15);
T = num(sortIndex,16);
VZ = num(sortIndex,17);
XOM = num(sortIndex,18);
% DATE_num = datenum(DATE,'dd/mm/yy'); % no hour,minute and second in your date data
hf=figure('Units','normalized','Position',[0.05 0.05 0.9 0.7]);
plot ( DATE_num , BA , 'r'), hold on, grid on % hold if you want to plot on the same figure, add grid
title('Stock Symbols');
xlabel('Dates');
ylabel('Stock Symbols ($)');
plot ( DATE_num , BAC, 'b')
plot ( DATE_num , CAT ,'k')
plot ( DATE_num , CSCO, 'g')
plot ( DATE_num , DIS, 'm')
plot ( DATE_num , GE, 'c')
% Add legend if wanted
legend('BA','BAC','CAT','CSCO','DIS','GE','Location','Best')
% Set axes labels
mindate=min(DATE_num);
maxdate=max(DATE_num);
ha=get(hf,'CurrentAxes');
set(ha,'XTickLabelMode','manual','XTickMode','manual','XLimMode','manual',...
'XLim',[mindate-15 maxdate+15],'XTick',linspace(mindate,maxdate,10));
% % % xticklabels=datestr(get(ha,'XTick'),24); % Will be used to label the X axis, format is dd/mm/yyyy
% % % set(ha,'XTickLabel',xticklabels);
% % %
dateaxis('x',1);
All it does not is open a chart, but nothing gets plotted. I don't get any errors.
Below is a sample file to download and put in the Matlab folder (so you don't have to spend a lot of time creating your another Excel file).
http://www.mediafire.com/view/?gjd29zoo7p4c8kw