# how to correct the error in finding neighbor pixels in an 3x3 window? how many input arguments for an max() function have?

1 visualizzazione (ultimi 30 giorni)
sheno39 il 9 Ott 2013
Commentato: Ashish Uthama il 10 Ott 2013
I=[2 3 10 4 6; 1 4 7 5 3; 5 2 8 4 3;8 2 1 7 3;1 9 8 3 4;];
[x y]=size(D);
m=1;
n=1;
for i=2:x-1
for j=2:y-1
I1(m,n)=max(max(D(i-1,j-1:j+1),D(i,j-1),D(i,j+1),D(i+1,j-1:j+1)));
n=n+1;
end
m=m+1;
n=1;
end
I1=I1(1:x-2,1:y-2);
error: Error using max Too many input arguments.
Error in sampl1 (line 9) I1(m,n)=max(max(D(i-1,j-1:j+1),D(i,j-1),D(i,j+1),D(i+1,j-1:j+1)));
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposte (1)

ES il 9 Ott 2013
max ideally takes one argument, a vector or matrix and returns the maximum element(s) (elements in case the passed input is a matrix).
max also takes two arguments.
But foryour case, you can form a matrix x=[D(i-1,j-1:j+1),D(i,j-1),D(i,j+1),D(i+1,j-1:j+1)] and do a max on x like
max(x)
##### 3 CommentiMostra 1 commento meno recenteNascondi 1 commento meno recente
Walter Roberson il 9 Ott 2013
max can also take three arguments. When it is given 2 arguments, it always proceeds element-by-element. When it is given three arguments with the second argument empty, it uses the third as the dimension number to take the maximum over.
Ashish Uthama il 10 Ott 2013

Accedi per commentare.

### Categorie

Scopri di più su Discrete Data Plots 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