필터 지우기
필터 지우기

"Error using == Matrix dimensions must agree" Finding max point on a plot?

조회 수: 2 (최근 30일)
Abi Marie
Abi Marie 2016년 8월 22일
답변: KSSV 2016년 8월 22일
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 440574x2 and the dimensions of max(a) are 1x2.
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 :)
  댓글 수: 1
Adam
Adam 2016년 8월 22일
What are you trying to find with your max? Do you want to find the max, ignoring the structure of your code containing 2 columns or do you want the max per column?
In the first case use
max( a(:) )
In the second case the 1x2 result array that you get will contain the max from each column which will likely be on different rows to each other so this cannot then be compared against the original 'a' matrix.

댓글을 달려면 로그인하십시오.

채택된 답변

KSSV
KSSV 2016년 8월 22일
Use simply max() to find the position of maximum of array.
Eg:
k = rand(100,1) ;
[value,index] = max(k) ;

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2016년 8월 22일
Maybe you want
indexmax = find(a==max(a))
Which can be done otherwise
[~,indexmax]=max(a)

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by