简体   繁体   English

图像处理(Matlab):索引超出矩阵尺寸

[英]Image processing (Matlab): index exceeds the matrix dimensions

well, I am new to matlab programming and I have been battling on the indexing issues. 好吧,我是Matlab编程的新手,我一直在努力解决索引问题。 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. 我试图运行代码,但触发了一个错误,提示“索引超出了矩阵的尺寸。据我所知,我认为这是因为(:,perm(1:nclus))高于矩阵的尺寸。我想知道我该如何解决这个问题。

Note that X: is the input points in the columns nclus: number of clusters. 请注意,X:是列nclus:簇数中的输入点。

I highly appreciate if you guys clarify to me the error cause and the possible solution for it. 非常感谢你们向我澄清错误原因以及可能的解决方案。

Thank you 谢谢

Sami 佐美

Guessing that you just want to get nclus random columns from a 2 dimensional matrix X , try this: 猜测您只想从二维矩阵X获取nclus随机列,请尝试以下操作:

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. 您遇到的错误不应源于X调用过多的尺寸,这可能是因为超出了perm的尺寸。 Try running this line by line: 尝试逐行运行此命令:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM