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
Matt J 2020년 10월 2일

0 개 추천

fzero(@(x)interp1(A,x), [1,numel(A)])

댓글 수: 13

Babu Sankhi
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?
Matt J
Matt J 2020년 10월 2일
편집: Matt J 2020년 10월 2일
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
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
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
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 ?
Matt J
Matt J 2020년 10월 3일
편집: Matt J 2020년 10월 3일
In what way is the answer wrong? You realize that a=60.46 is the index at which the root occurs, correct?
Babu Sankhi
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.
Matt J
Matt J 2020년 10월 3일
편집: Matt J 2020년 10월 3일
I told you before. You should split the data into two separate curves.
Babu Sankhi
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?
Matt J
Matt J 2020년 10월 4일
편집: Matt J 2020년 10월 4일
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
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
Matt J
Matt J 2020년 10월 4일
편집: Matt J 2020년 10월 4일
xvalue = fzero( @(xq)interp1(x,y+4.54,xq) , [min(x),max(x)] )% x value at y=-4.54
Babu Sankhi
Babu Sankhi 2020년 10월 4일
Thank you ,
It worked now.

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

추가 답변 (0개)

질문:

2020년 10월 1일

댓글:

2020년 10월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by