0

I have used this method to add to arrays in other programs but this it doesn't seem to work. I am confused and can't find a answer to the problem.

Error:

The sample size is: Error using horzcat
CAT arguments dimensions are not consistent.

Error in CalculateElo (line 14) playerGroup = [playerGroup r];

Code:

function [accuracy] = CalculateElo (referenceElo , sampleSize, lower, upper)

fprintf('The sample size is: %d', sampleSize);

% Popoulate an new array
playerGroup = [];
playerGroup = [playerGroup referenceElo];

for i=1:(sampleSize - 1)
    %Create group size
    a = 0;
    b = 2000;
    r = (b-a).*rand(1000,1) + a;
    playerGroup = [playerGroup r];
end
1
  • rand(1000,1) is 1000 element row vecor. You cant add it to as a new column to playerGroup if it has different number of rows. Commented Feb 26, 2015 at 3:48

1 Answer 1

1

An expression like [x y] tries to concatenate the arrays x and y along dimension 2. Each row of an array in Matlab must have the same length (similarly, each column must have the same length). Hence, if size(x,1) = size(y,1), [x y] will return an array with size equal to size(x,1) along the first dimension and size(x,2)+size(y,2) along the second dimension. Otherwise you will get a cat error like the one you show.

r has size (1000,1), so unless the first dimension of referenceElo has size 1000, you will get a cat error.

You didn't mention the size of referenceElo, but I'm guessing it's a single number. You could use the ' (transpose) operator to write

playerGroup = [playerGroup r'];

returning an array of size (1,1001). Or you could use an expression of form [x;y], which concatenates along dimension 1:

playerGroup = [playerGroup;r];

returning an array of size (1001,1).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.