user2040072
user2040072

Reputation: 15

Image processing (Matlab): index exceeds the matrix dimensions

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

Upvotes: 0

Views: 616

Answers (1)

Dennis Jaheruddin
Dennis Jaheruddin

Reputation: 21563

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)

Upvotes: 1

Related Questions