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

Hi I have a curve,I want to find x and y coordinate of the maximum value Thanks

1 件のコメント

James Tursa
James Tursa 2015 年 6 月 4 日
In what form do you have the curve? A one line definition? A function file? Or what?

サインインしてコメントする。

 採用された回答

Image Analyst
Image Analyst 2015 年 6 月 4 日
If x and y are in arrays, how about
[maxY, indexOfMaxY] = max(y);
xAtMaxY = x(indexOfMaxY);

9 件のコメント

yousef Yousef
yousef Yousef 2015 年 6 月 4 日
y is a curve and not matrix
James Tursa
James Tursa 2015 年 6 月 4 日
What is class(y)? I.e., in what form to you have the curve?
yousef Yousef
yousef Yousef 2015 年 6 月 4 日
Image Analyst
Image Analyst 2015 年 6 月 4 日
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.
yousef Yousef
yousef Yousef 2015 年 6 月 4 日
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
Image Analyst
Image Analyst 2015 年 6 月 4 日
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.
yousef Yousef
yousef Yousef 2015 年 6 月 5 日
編集済み: Image Analyst 2015 年 6 月 5 日
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
yousef Yousef
yousef Yousef 2015 年 6 月 5 日
Hi,Thanks for you feeling,you will find every thing in the attached file. Thanks
Image Analyst
Image Analyst 2015 年 6 月 5 日
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 件)

yousef Yousef
yousef Yousef 2015 年 6 月 5 日
編集済み: yousef Yousef 2015 年 6 月 5 日

0 投票

  • 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)
yousef Yousef
yousef Yousef 2015 年 6 月 5 日
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?
yousef Yousef
yousef Yousef 2015 年 6 月 5 日
I have got -180 once and 317 another time but I don't understand how come
Alfonso Nieto-Castanon
Alfonso Nieto-Castanon 2015 年 6 月 5 日
編集済み: Alfonso Nieto-Castanon 2015 年 6 月 5 日
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));
yousef Yousef
yousef Yousef 2015 年 6 月 5 日
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 ExchangeGraphics Performance についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by