MATLAB: How can i write F=(1/N).*f​.*double(a​).*f; correctly, the ,matlab(2015a) keeps giving me errors

element-wiseequationMATLABmatrix dimensions must agreetimes

I am trying to do the simulation for the walsh code, here is the code….
%Walsh Transform.
clear;
% Reading the image file into variable 'a'.
a=imread('len.jpg');
%x=rgb2gray(a);
N=length(a);
%Walsh Transform computation
n=log2(N);
n=1+fix(n);
f=ones(N,N);
for x=1:N;
for u=1:N
p=dec2bin(x-1,n);
q=dec2bin(u-1,n);
for i=1:n;
f(x,u)=f(x,u)*((-1)^(p(n+1-i)*q(i)));
end;
end;
end
*F=(1/N).*f.*double(a).*f;-----i keep having an error at this level*
% Shifting the Fourier spectrum to the center of the frequency square.
for i=1:N/2;
for j=1:N/2
G(i+N/2,j+N/2)=F(i,j);
end;
end
for i=N/2+1:N;
for j=1:N/2
G(i-N/2,j+N/2)=F(i,j);
end;
end
for i=1:N/2;
for j=N/2+1:N
G(i+N/2,j-N/2)=F(i,j);
end;
end
for i=N/2+1:N;
for j=N/2+1:N
G(i-N/2,j-N/2)=F(i,j);
end;
end
% Computing and scaling the logarithmic Walsh spectrum.
H=log(1+abs(G));
for i=1:N
H(i,:)=H(i,:)*255/abs(max(H(i,:)));
end
% Changing the color map to gray scale (8 bits).
colormap(gray(255));
% Showing the main image and its Walsh spectrum.
subplot(2,2,1),image(a),title('Main image');
subplot(2,2,2),image(abs(G)),title('Walsh spectrum');
subplot(2,2,3),image(H),title('Logarithmic scaled Walsh spectrum');
if true
if true
% code

end
% code
end

Best Answer

You are trying to multiply two arrays which have totally different sizes:
>> a = rand(23,99,3);
>> N = length(a);
>> f = ones(N,N);
>> F = (1/N).*f.*double(a).*f
Error using .*
Matrix dimensions must agree.
In fact the basic problem is this multiplication:
>> f.*a
Error using .*
Matrix dimensions must agree.
So lets have a look at the sizes of those arrays:
>> size(f)
ans =
99 99
>> size(a)
ans =
23 99 3
The times documentation clearly states that " Inputs A and B must be the same size unless one is a scalar". Are your two arrays the same size ? What do expect MATLAB to do ?
Related Question