finding the two coordinates
显示 更早的评论
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
采纳的回答
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
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.
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
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)
