# How to solve "Index exceeds matrix dimensions" error?

3 visualizzazioni (ultimi 30 giorni)
noor shahida il 24 Giu 2013
Commentato: Jan il 23 Ott 2017
Hi all.. I have a coding here..which is when i run it appear "Index exceeds matrix dimensions".Can anyone help.
NumBasei = 1;
for NBi = 1:InnerRings-1;
NumBasei = NumBasei + 6*NBi;
end
B_dist = sqrt(B_x.^2 + B_y.^2);
Bdata = [B_dist' B_x' B_y' B_l']; % distance % x % y % label
Bdata_s = sortrows(Bdata);
Bdata_in = Bdata_s(1:NumBasei , :);
scatter(Bdata_in(:,2)',Bdata_in(:,3)',20,'filled','w');
thanks.
##### 2 CommentiMostra NessunoNascondi Nessuno
Jan il 24 Giu 2013
Please post the complete error message and mention in which line the error occurs. We cannot run your function, because we do not have your data.
noor shahida il 24 Giu 2013
error come from Bdata_in = Bdata_s(1:NumBasei , :);
NumBase = length(B_x); for BC = 1:NumBase; Bx = B_x(1,BC); By = B_y(1,BC); if draw_bounds==1; line([Bx-R*cosd(60) Bx+R*cosd(60) Bx+R Bx+R*cosd(60) Bx-R*cosd(60)... Bx-R Bx-R*cosd(60)],[By+R*sind(60) By+R*sind(60) ... By By-R*sind(60) By-R*sind(60) By By+R*sind(60)]); hold on end fnb = floor(NumBase/4); if (BC == fnb)||(BC==2*fnb)||(BC==3*fnb); end scatter(Bx,By,70,'filled');
end
NumBasei = 1; for NBi = 1:InnerRings-1; NumBasei = NumBasei + 6*NBi; end B_dist = sqrt(B_x.^2 + B_y.^2); Bdata = [B_dist' B_x' B_y' B_l']; % distance % x % y % label Bdata_s = sortrows(Bdata); Bdata_in = Bdata_s(1:NumBasei , :); scatter(Bdata_in(:,2)',Bdata_in(:,3)',20,'filled','w');

Accedi per commentare.

### Risposte (5)

Jan il 24 Giu 2013
You can use the debugger to find out more details:
dbstop if error
Then start the program again. It stops, when the error occurs. Then you can inspect the indices and the available dimensions.
##### 3 CommentiMostra 1 commento meno recenteNascondi 1 commento meno recente
noor shahida il 24 Giu 2013
ihave try it,but still error at the same place.
Jan il 24 Giu 2013
Of course the error appears in the same place. This is the nature of a debugger. But now you can check the size of the locally used variables and find out, why Bdata_s has les than NumBasei rows.

Accedi per commentare.

Hugo il 24 Giu 2013
At first glance, the error should appear as a consequence of the line
Bdata_in = Bdata_s(1:NumBasei , :);
So, I would recommend you to compare the value of "NumBasei" with the number of rows in Bdata_s. If NumBasei is greater than size(Bdata_s,1), then you should do something about it.
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

poongothai rajan il 30 Mag 2014
[rows, cols, numOfBands] = size(T); % totalPixelsOfImage = rows*cols*numOfBands; image = rgb2hsv(T);
% split image into h, s & v planes h = image(:, :, 1); s = image(:, :, 2); v = image(:, :, 3);
I have a coding here..which is when i run it appear "Index exceeds matrix dimensions".Can anyone help.
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

poongothai rajan il 30 Mag 2014
I have a coding here..which is when i run it appear "Index exceeds matrix dimensions".Can anyone help.
[rows, cols, numOfBands] = size(T);% totalPixelsOfImage = rows*cols*numOfBands; image = rgb2hsv(T);(T is the training database)
% split image into h, s & v planes
h = image(:, :, 1);
s = image(:, :, 2);
v = image(:, :, 3);
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

Nikhil Shrestha il 23 Ott 2017
Modificato: Walter Roberson il 23 Ott 2017
openExample('images/BoostLocalColorContrastUsingColorModeExample')
Index exceeds matrix dimensions.
Error in openExample (line 10)
##### 3 CommentiMostra 1 commento meno recenteNascondi 1 commento meno recente
Walter Roberson il 23 Ott 2017
Which MATLAB version are you using?
What shows up for
which -all openExample
You would expect to see only toolbox/matlab/helptools/openExample.m . In R2017b, openExample.m does not have code corresponding to the error message you show.
Jan il 23 Ott 2017
@Nikhil Shrestha: Please open a new thread for a new question. If you only hijack another thread, you cannot accept an answer, but cause confusion, because it is not longer clear to which question an answer belongs to. After creating a new question, p0lease remove this "pseudo-answer"- Thanks.

Accedi per commentare.

### Categorie

Scopri di più su Matrix Indexing in Help Center e File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by