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
採用された回答
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!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)
