0
votes

well, I am new to matlab programming and I have been battling on the indexing issues. I am currently working on image processing which so far drive me crazy. anyways, lets jump to the questions. I have the following code

perm=randperm(size(X,2));
CX=X(:,perm(1:nclus));

I tried to run the code but it triggers an error saying " Index exceeds the matrix dimensions. To my humble knowledge I think it is because the (:,perm(1:nclus)) is higher than the matrix dimensions. I would like to know how can i solve this problem.

Note that X: is the input points in the columns nclus: number of clusters.

I highly appreciate if you guys clarify to me the error cause and the possible solution for it.

Thank you

Sami

1
How you define size of X? E.g., what number of columns in X matrix?Danil Asotsky
What exactly are you trying to achieve?Dennis Jaheruddin
Danil, X is the input points in the columns in the images that are used as a training data.user2040072
Are you certain that nclus <= size(X, 2) ?Dan
Yes the number of clusters are less or equal to the size of 2 dimensional matrix (x).. Thank you Dennisuser2040072

1 Answers

1
votes

Guessing that you just want to get nclus random columns from a 2 dimensional matrix X, try this:

perm=randperm(size(X,2));
CX=X(:,perm<=nclus);

The error that you experience should not come from X being called with too many dimensions, it is probably because the dimensions of perm are exceeded. Try running this line by line:

perm = randperm(size(X,2)); %Should be ok
idx = perm(1:nclus); %Probably fails
X(:,idx)