MATLAB: Getting this error

m-fileMATLAB

??? Index exceeds matrix dimensions.
Error in ==> C:\Documents and Settings\krishnendu\Desktop\Chared ICA Code\CreateInitialEmpires.m
On line 4 ==> AllImperialistsCost = InitialCost(1:AlgorithmParams.NumOfInitialImperialists,:);
by using the code
AllImperialistsCost = InitialCost(1:AlgorithmParams.NumOfInitialImperialists,:);
AlgorithmParams.NumOfInitialImperialists=2;
initialcost is a matrix like [1 2 3 4 5]
where is the error?
X(1:2,:);
what does it mean?

Best Answer

This may be a confusion with rows and columns. E.g. this code here fails:
a=[1 2 3 ]
a(1:2, :)
Beacuse a is an 1x3 matrix and a(1:2, :) tries to access a nonexisting second row.