Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

Index exceeds matrix dimensions

Asked by Kevin van Berkel on 10 Jun 2013

Hello all,

Anyone knows what goes wrong? I receive this error:

Index exceeds matrix dimensions.

on the following code:

X = [ones(M,1), r(:,t,1), r(:,t,2), r(:,t,3), r(:,t,4), r(:,t,5),...
z(:,t,1), z(:,t,1).^2, z(:,t,2), z(:,t,2).^2, z(:,t,3),...
z(:,t,3).^2, z(:,t,4), z(:,t,4).^2, z(:,t,5), z(:,t,5).^2, ...
z(:,t,1).*z(:,t,2), z(:,t,1).*z(:,t,3),z(:,t,1).*z(:,t,4),...
z(:,t,1).*z(:,t,5), z(:,t,2).*z(:,t,3), z(:,t,2).*z(:,t,4),...
z(:,t,2).*z(:,t,5), z(:,t,3).*z(:,t,4), z(:,t,3).*z(:,t,5),...
z(:,t,4).*z(:,t,5)];

referring to this function

function Weights = Portfolio_fmincon_multiple_it_state_vb_bs(r,z,gamma,r_f,constr_ON,... it_ON, N_max)

Help would be much appreciated!!

Thanks.

Kevin

0 Comments

Kevin van Berkel

Products

No products are associated with this question.

2 Answers

Answer by Azzi Abdelmalek on 10 Jun 2013

You should look at the sizes of r and z, and check if their indices do not exceed those sizes

3 Comments

Azzi Abdelmalek on 10 Jun 2013

Kevin van Berkel commented

Hi Azzi, thanks for your reply.

Both r and z are 1000x20 (double) matrices.

This code is previous before the 'X=...' code:

[M,T,N_assets] = size(r);
x = zeros(M,T-1,N_assets);
x_0 = zeros(N_assets,1);
options = optimset('Display','off','TolFun',1e-6,'LargeScale','off');
if constr_ON==1
LB = zeros(N_assets,1);
UB = ones(N_assets,1);
else
  LB = [];
  UB = [];
end

So wat should I check?

THanks for your help!

Azzi Abdelmalek on 10 Jun 2013

You said that r is a 1000x20 double, then why to write

 r(:,t,3) 
Kevin van Berkel on 10 Jun 2013

This should capture the multiple assets included.. But it's more a gues..

Azzi Abdelmalek
Answer by Kevin van Berkel on 10 Jun 2013

This should capture the multiple assets included.. But it's more a gues..

1 Comment

Azzi Abdelmalek on 10 Jun 2013

Kevin, if you want to add a comment, just click on comment on this answer

Kevin van Berkel

Contact us