如何在matlab中删除数组索引超出范围的错误

时间:2014-06-28 11:46:01

标签: matlab

这是我的代码,我有一个关于数组索引超出范围的错误。 plzz帮助我纠正它

I = imread('E:\degraded images\village.jpg');
imshow(I)


I = im2double(I);
I = log(1 + I);

M = 2*size(I,1) + 1;
N = 2*size(I,2) + 1;

sigma = 10;

[X, Y] = meshgrid(1:N,1:M);
centerX = ceil(N/2);
centerY = ceil(M/2);
gaussianNumerator = (X - centerX).^2 + (Y - centerY).^2;
H = exp(-gaussianNumerator./(2*sigma.^2));
H = 1 - H;

imshow(H,'InitialMagnification',25)

H = fftshift(H);

If = fft2(I, M, N);
Iout = real(ifft2(H.*If)); ** here the code has error . ??? Error using ==> times Number of array dimensions must match for binary array op.**

1 个答案:

答案 0 :(得分:0)

H是2-D而If是3-D。您可以将repmatH或子集If一起使用。我不知道哪一个对你的情况是正确的。例如,

rempat( H, [1, 1, 3 ] ) .* If;

H .* If(:,:,ind);  % ind is the index of the 2-D array you want to subset