MATLAB: “Error using == Matrix dimensions must agree” Finding max point on a plot

errorgraphmatrixplot

My code is:
%Plotting the frequency spectrum.
%Frequency domain.
f = -Fs/2:Fs/(n-1):Fs/2;
z = fftshift(fft(A3));
%Magnitude graph.
a = abs(z);
figure(2)
plot(f,a,'b')
%Finding the maximum frequency.
indexmax = find(max(a) == a);
amax = a(indexmax); %Doesn't work.
fmax = f(indexmax);
And it's saying the problem is at "indexmax = find(max(a) == a);"
The dimensions of a are 440574×2 and the dimensions of max(a) are 1×2.
I'm relatively new to Matlab so I'm guessing it's something obvious but I've tried everything I can think of and I can't figure out what's going on.
Thanks 🙂

Best Answer

Use simply max() to find the position of maximum of array.
Eg:
k = rand(100,1) ;
[value,index] = max(k) ;