Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Index exceeds matrix dimensions.

1 vue (au cours des 30 derniers jours)
Dani D
Dani D le 18 Nov 2016
Clôturé : MATLAB Answer Bot le 20 Août 2021
Hello, I have an error :( Index exceeds matrix dimensions.
clc;
clear;
close all;
I = imread('C:\Users\Pictures\sgs.jpg');
I = rgb2gray(I);
[m , n ] = size(I);
MaxI = 0;
for i = 1:n
for j = 1:m
if (I(i,j) > MaxI)
MaxI = I(i,j);
end
end
end

Réponses (1)

Adam
Adam le 18 Nov 2016
[m , n ] = size(I);
gives you the number of rows and columns in m and n respectively.
You then loop i up to n and j up to m, but use
I(i,j)
which is switching round the rows with the columns so unless you have a square image you will see this error.

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by