finding the two coordinates
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
Hi all,
I have a plot from experimental data. I want to find the two values of x that corresponds to y=0. Basically, I want to find the coordinates A and B ( in both coordinates y=0) in the file attached below. I tried by using " find (x==0)" but it gave me blank. Can you please help how can I find them?
Thank you
채택된 답변
Matt J
2020년 10월 2일
fzero(@(x)interp1(A,x), [1,numel(A)])
댓글 수: 13
Babu Sankhi
2020년 10월 2일
편집: Babu Sankhi
2020년 10월 2일
I am sorry it did not work? It gave me the error like this:
Error using fzero (line 246)
FZERO cannot continue because user-supplied function_handle ==> @(x)interp1(0,x) failed with the error below.
Interpolation requires at least two sample points in each dimension.
Error in Hallode (line 42)
fzero(@(x)interp1(0,x), [1,numel(0)])
>>
Perhaps I donot have any function. I just have a plot (y versus x) from my experimental data. I need to find the the points on the plots at which y becomes 0. There are two coordinates corresponding to this. Can you help me more?
It looks like instead of passing in a vector A, you passed in the scalar 0. To see how it's suposed to work, suppose we have, for example,
A=[-ones(1,10), -.25,0.5, +ones(1,10)]; plot(A,'x-');

Now, do the thing:
>> fzero(@(x)interp1(A,x), [1,numel(A)])
ans =
11.3333
Babu Sankhi
2020년 10월 2일
편집: Babu Sankhi
2020년 10월 2일
It gave me error like that . ( BTW I have to get two values of x at y=0). Can you please help me more?
>> fzero(@(x)interp1(y,x), [1,numel(y)])
Error using fzero (line 290)
The function values at the interval endpoints must differ in sign.
thank you
Matt J
2020년 10월 2일
BTW I have to get two values of x at y=0
Just apply the method twice, once to each curve.
Babu Sankhi
2020년 10월 2일
편집: Babu Sankhi
2020년 10월 2일
I tried that way as well. But it did nt give the right one!
Moreover I should get the two values of X from single plot can we do that?
can you please help me ?

In what way is the answer wrong? You realize that a=60.46 is the index at which the root occurs, correct?
Babu Sankhi
2020년 10월 3일
편집: Babu Sankhi
2020년 10월 3일
Rather than this , interpo1( y,x,0) worked well. BTW thank you. But still I am needing idea if Y=0 does not have unique value( in my case there are two values of X at Y=0 and i need to get both) . It would great if you can help me in this regard.
I told you before. You should split the data into two separate curves.
Babu Sankhi
2020년 10월 4일
I tried by splitting the data and tried to find the x values for certain y value by using interpolation. It always gave me the error as seen clear in the figure attached below. I have also attached the one set of data tha I used. Can you please help me to figure out the problem?

It is not terribly useful to see an image of your code. It is best to present the code in text form so that we can copy, paste and run it. Also, this data does not have any locations where Y=0. Are you trying to find the X for which Y=-4.54?
Babu Sankhi
2020년 10월 4일
편집: Babu Sankhi
2020년 10월 4일
figure(3);
dt=importdata('try.txt');
x=dt(:,1);
y=dt(:,2);
plot(x,y,'r--o')
xlabel('X');
ylabel('Y');
set(gca,'Fontsize',18)
xvalue =interp1(y,x,-4.54);% x value at y=-4.54
I have pasted codes above,
Yes I am trying to find the X for which Y=-4.54. Can you help me more?
Thank you
xvalue = fzero( @(xq)interp1(x,y+4.54,xq) , [min(x),max(x)] )% x value at y=-4.54
Babu Sankhi
2020년 10월 4일
Thank you ,
It worked now.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Exploration and Visualization에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
