From: Aris David on
I have the following section of code in MATLAB, basically it reads the historical data of the given symbols.

startdate = '01012010';
enddate = '20042010';
freq = 'd';

stocks = hist_stock_data(startdate, enddate, 'AAL.L', 'ABF.L', ...
'ADM.L', 'AGK.L', 'AMEC.L', 'ANTO.L', 'ARM.L', 'ATST.L',...
'frequency', freq);

for i = 1:8
data(:, i) = stocks(i).AdjClose;
end

For the 8 tickers above, 7 have a time series prices for 64 days and 1 has time series prices for 63 days. The problem is when I run this code I will get the error message below

??? Subscripted assignment dimension mismatch.

Error in ==> FTSEallshare at 37
data(:, i) = stocks(i).AdjClose;

what actually happens is MATLAB will store the prices for tickers with 64 days and bypass the one with 63 days.

Can anyone shed a light as to how can I overcome this issue? I can provide the full code if need be
From: Walter Roberson on
Aris David wrote:
> I have the following section of code in MATLAB, basically it reads the
> historical data of the given symbols.
>
> startdate = '01012010';
> enddate = '20042010';
> freq = 'd';
> stocks = hist_stock_data(startdate, enddate, 'AAL.L', 'ABF.L', ...
> 'ADM.L', 'AGK.L', 'AMEC.L', 'ANTO.L', 'ARM.L', 'ATST.L',...
> 'frequency', freq);
>
> for i = 1:8
> data(:, i) = stocks(i).AdjClose;
> end
>
> For the 8 tickers above, 7 have a time series prices for 64 days and 1
> has time series prices for 63 days. The problem is when I run this code
> I will get the error message below
>
> ??? Subscripted assignment dimension mismatch.

data = nan( max(cellfun(@length, {stocks.AdjClose})), 8 );
for i = 1:8
data(1:length(stocks(i).AdjClose) = stocks(i).AdjClose
end


Now the data array will automatically adjust itself to the length of the
largest time series, and any time series that is shorter than the maximum
length will have one or more nan in their final column entries.
From: Aris David on
Thanks Walter.


"Aris David" <aris.d.david(a)gmail.com> wrote in message <hqqh2p$8vo$1(a)fred.mathworks.com>...
> I have the following section of code in MATLAB, basically it reads the historical data of the given symbols.
>
> startdate = '01012010';
> enddate = '20042010';
> freq = 'd';
>
> stocks = hist_stock_data(startdate, enddate, 'AAL.L', 'ABF.L', ...
> 'ADM.L', 'AGK.L', 'AMEC.L', 'ANTO.L', 'ARM.L', 'ATST.L',...
> 'frequency', freq);
>
> for i = 1:8
> data(:, i) = stocks(i).AdjClose;
> end
>
> For the 8 tickers above, 7 have a time series prices for 64 days and 1 has time series prices for 63 days. The problem is when I run this code I will get the error message below
>
> ??? Subscripted assignment dimension mismatch.
>
> Error in ==> FTSEallshare at 37
> data(:, i) = stocks(i).AdjClose;
>
> what actually happens is MATLAB will store the prices for tickers with 64 days and bypass the one with 63 days.
>
> Can anyone shed a light as to how can I overcome this issue? I can provide the full code if need be
 | 
Pages: 1
Prev: Regarding Matlab cwt function
Next: avoid forloop