How to find the maximum value of C that corresponds to a set of X,Y coordinates?

조회 수: 2 (최근 30일)
I have a spectrogram plot that contains X,Y and C. I want to find the maximum values of C from that spectrogram and also the XY coordinates that they correspond to. I have this so far but I am not sure how to get the X,Y coordinates that each value of max C corresponds to.
imagesc(X,Y,10*log10(C))
maxC = max(C);

채택된 답변

Star Strider
Star Strider 2022년 7월 29일
The spectrogram plot is actually a surf plot with the view set to display it looking from the top, so the ‘Z’ values will give you all the information you want.
One way of getting that information from the spectrogram is to use the medfreq funciton. See Track Chirps in Audio Signal for an example.
  댓글 수: 2
Brianna Miranda
Brianna Miranda 2022년 7월 29일
This does not address my question. I am asking how to find the x & y coordinates of the matrix that correspond to the maximum z value. Your response only finds the average value of the maximum z value. I want all maximum z values that correspond to every x coordinate and a list of all the x and y values those z values correspond to.
Star Strider
Star Strider 2022년 7월 29일
With a spectrogram, the ‘maximum’ can be defined as the maximum value of the ‘Z’ matrix (the eqay solution), or the maximum frequency with respect to time (the solution that the link I posted could be useful to find).
The maximum value of the ‘Z’ matrix is simply:
[r,c] = find(Z == max(Z(:))
so for example —
[X,Y] = ndgrid(1:0.1:5);
Z = randn(size(X))
Z = 41×41
-0.0639 -2.4202 -0.5892 -0.3153 -1.2375 0.2582 0.5664 -0.0020 -0.4781 -0.4400 0.3104 -1.6870 2.3617 0.1904 0.4709 0.5604 0.9655 1.4496 0.8379 1.5481 -0.2459 0.1577 2.6907 1.9585 -0.7600 0.8633 -0.0593 -0.0278 -0.7414 0.2447 -0.8915 -1.3448 -0.9731 1.4001 -1.4113 0.0759 -0.3949 1.0819 -1.2504 0.2395 -0.5119 0.4586 -0.9246 0.8510 1.2941 1.2805 -0.4253 -0.0403 1.7856 -1.3657 1.5380 -0.8891 -0.9842 0.6527 -2.5084 -1.8022 0.3371 1.2054 -0.6248 -0.9365 0.0217 0.7413 0.9703 -1.3422 -0.6889 2.4894 -0.8549 -0.4740 -0.2225 -0.5694 -2.0222 1.1507 -0.2375 -2.5342 0.8704 0.9467 -1.1114 -2.4286 -0.3480 -1.4527 0.8740 -0.5818 -1.1733 0.6569 1.0697 0.2519 -1.4657 0.9207 -0.5496 0.5370 -0.3532 0.4664 -1.1207 -0.2304 0.0524 -0.0722 0.3842 -0.5589 -1.0253 0.6298 -0.3426 -0.8348 -2.4134 1.7251 -2.4607 -1.6548 -0.1585 -1.3724 1.6503 -0.1679 -0.6309 -0.2147 -0.6524 0.7183 -2.7147 1.3611 1.0592 -0.5393 1.2776 0.6410 0.7345 -0.1412 1.6778 -0.8870 0.1101 -0.2241 0.2429 1.8206 -0.6441 1.5836 -0.6047 1.9053 1.9305 0.3951 0.5758 -1.3763 0.2552 -1.7303 -0.0525 3.0846 -1.0426 0.0874 -0.3216 0.1369 0.2692 1.2349 0.5056 -1.2016 -0.8287 -0.7030 -1.6341 -0.6052 0.1854 -0.5525 -1.5532 -1.9856 0.6408 1.9057 -1.3372 1.1240 -0.4402 -1.4120 -0.1029 -0.5735 -0.2999 -0.0698 1.8575 0.2400 1.4729 0.6123 -0.0452 0.4546 0.5246 0.8361 2.2197 -0.6524 -0.1364 0.8422 0.4287 -0.7655 0.6935 0.9505 -0.1121 -1.8347 -1.2506 -1.0413 1.2313 -0.0750 -0.9505 0.1271 -0.5988 -1.3527 1.5817 0.4073 0.0950 -0.1533 -1.4091 1.1605 -1.0842 -0.9306 -0.3523 -1.8747 0.3412 1.2081 -2.6801 0.1715 0.0911 -0.1921 -1.0078 0.3955 0.1917 -0.5632 1.3781 1.4707 -0.7444 -1.0536 -0.4651 -0.4820 1.1504 -0.2833 1.1034 -0.0543 -0.1905 -0.2366 -2.0467 -0.1114 1.0882 -0.2817 0.5707 -0.7683 -1.1562 -0.3642 -1.0025 -0.7422 0.3502 -1.0852 -0.1734 1.7628 -0.7464 -0.8762 -1.6987 -0.3549 1.3508 -1.3206 -1.7158 0.6468 1.0099 -0.2371 0.2916 0.0334 0.3175 0.2897 -0.3463 1.5408 2.0720 0.1516 0.3823 -1.3584 1.1463 0.2069 1.2317 0.2429 1.4249 -0.0526 0.5708 -0.0585 0.1757 1.1555 -0.0869 -0.3246 1.1156 -0.5752 0.8764 -1.7859 -1.9668 -0.8118 0.0052 -1.3435 -0.5732 0.7530 -0.3858 0.0806 -0.7766 0.4792 2.5190 -0.6782 -1.3124 -0.4009 -1.7604 0.2375 -1.4506 0.9221 -0.9909 -0.3864 -0.5869 -0.0340 -1.1347 1.2365 -0.0547 -0.7845
[r,c] = find(Z == max(Z(:)))
r = 13
c = 9
maxZ = Z(r,c)
maxZ = 3.2838
figure
surf(X,Y,Z)
hold on
stem3(X(r,c),Y(r,c),Z(r,c), '^r', 'MarkerFaceColor','r')
hold off
grid on
.

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

추가 답변 (1개)

Voss
Voss 2022년 7월 29일
X = 1:3:31;
Y = 1:2:13;
C = rand(numel(Y),numel(X));
imagesc(X,Y,10*log10(C))
[maxC,idx] = max(C(:))
maxC = 0.9986
idx = 58
[yidx,xidx] = ind2sub(size(C),idx)
yidx = 2
xidx = 9
maxX = X(xidx)
maxX = 25
maxY = Y(yidx)
maxY = 3
line(maxX,maxY,'Marker','x','MarkerEdgeColor','r')

카테고리

Help CenterFile Exchange에서 Spectral Measurements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by