How to find the x and y coordinates of the maximum value in curve without defferntiaition

 采纳的回答

If x and y are in arrays, how about
[maxY, indexOfMaxY] = max(y);
xAtMaxY = x(indexOfMaxY);

9 个评论

What is class(y)? I.e., in what form to you have the curve?
So your data is in the form of a .PNG image file? Why not just display it then use ginput() or impoints() to indicate the origin and another point, and the max? If you know (0,0) is at row 1000, column 500, and (80, 12) is at row 0, column 1000, then you can get a scaling from pixels to actual graph units.
I don't understand what you mean,I showed you this image to give idea about my curve,the maximum is located at 10.7305 in y coordinates and I want to find the corresponding x coordinate,no body force you to answer
I know nobody's forcing me to answer but James and I are trying to answer to help you, if you'll allow it. We are trying to write code to help you but we don't know what kind of data we start with. Do you have a vector y that you created somehow in MATLAB? Evidently NOT because you did not say that the code I first gave worked for you. Do you have an image file? Do you have data brought in through an Analog-to-digital converter? Did you make y from some equation? I can't write any code to find the max of y if I don't have y. Please give us y in whatever form you have it - an equation, a .MAT file, a .PNG file, an Excel workbook, a .csv file, a text file - something, anything . We can't do anything until we get the data.
clc
clear all
format long
N=200;
doa=[20 60]/180*pi;
w=[pi/4 pi/4]';
M=10;
P=length(w);
lambda=150;
d=lambda/2;
snr=20;
D=zeros(P,M);
for k=1:P
D(k,:)=exp(-j*2*pi*d*sin(doa(k))/lambda*[0:M-1]);
end
D=D';
xx=2*exp(j*(w*[1:N]));
x=D*xx;
x=x+awgn(x,snr);
R=x*x';
[N,V]=eig(R);
NN=N(:,1:M-P);
theta=-90:0.5:90;
for ii=1:length(theta)
SS=zeros(1,length(M));
for jj=0:M-1
SS(1+jj)=exp(-j*2*jj*pi*d*sin(theta(ii)/180*pi)/lambda);
end
clc
clear all
format long
N=200;
doa=[20 60]/180*pi;
w=[pi/4 pi/4]';
M=10;
P=length(w);
lambda=150;
d=lambda/2;
snr=20;
D=zeros(P,M);
for k=1:P
D(k,:)=exp(-j*2*pi*d*sin(doa(k))/lambda*[0:M-1]);
end
D=D';
xx=2*exp(j*(w*[1:N]));
x=D*xx;
x=x+awgn(x,snr);
R=x*x';
[N,V]=eig(R);
NN=N(:,1:M-P);
theta=-90:0.5:90;
for ii=1:length(theta)
SS=zeros(1,length(M));
for jj=0:M-1
SS(1+jj)=exp(-j*2*jj*pi*d*sin(theta(ii)/180*pi)/lambda);
end
PP=SS*NN*NN'*SS';
Pmusic(ii)=abs(1/ PP);
end
Pmusic=10*log10(Pmusic/max(Pmusic));
plot(theta,Pmusic,'-k')
xlabel('angle \theta/degree')
ylabel('spectrum function P(\theta) /dB')
title('DOA estimation based on MUSIC algorithm')
grid on
PP=SS*NN*NN'*SS';
Pmusic(ii)=abs(1/ PP);
end
Pmusic=10*log10(Pmusic/max(Pmusic));
plot(theta,Pmusic,'-k')
xlabel('angle \theta/degree')
ylabel('spectrum function P(\theta) /dB')
title('DOA estimation based on MUSIC algorithm')
grid on
Hi,Thanks for you feeling,you will find every thing in the attached file. Thanks
I hope someone with the Communications toolbox can help you. I don't have that so I can't run your code, specifically the awgn() function. I did format it for you though and added the Communications Toolbox to the product list above.

请先登录,再进行评论。

更多回答(1 个)

  • z=abs(P);
  • zz=round(z);
  • ymax=max(zz);
  • xmax=THETA(find (zz==ymax));
  • However ,if somebody has better solution,I kindly ask hem or her to provide me with.Thanks

7 个评论

that looks fine, remove the round operation or better yet use ImageAnalyst solution above (replacing y with abs(P) and x with THETA)
when I remove "round",the answers are quite different than whats shown in the graph,for example with "round" I get [-180 0 180],from the graph the answer is zero.However,if I don't use it I get -180 which is not correct
from your code and from your graph, theta is defined from -90 to 90, so it is hard to imagine how you could get -180 as theta(indexOfMaxY), could you please clarify?
I have got -180 once and 317 another time but I don't understand how come
Could you copy and paste the following code and report the result figure and values displayed in the command window?
figure;
plot(theta,Pmusic);
[maxP,maxIdx]=max(Pmusic);
fprintf('Maximum value %f at theta=%f\n',maxP,theta(maxIdx));
Thanks I think it is working great.But I still need to run it so many times to be sure.I will assure you if there is a problem in the results with this way of solving or not. Thanks a lot
great, if that works please accept ImageAnalyst solution above since this was basically his original suggestion

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Graphics Performance 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by