Trying to find an x value from a certain y value on my graph

75 ビュー (過去 30 日間)
Tom Goodland
Tom Goodland 2022 年 1 月 17 日
編集済み: Star Strider 2022 年 1 月 17 日
I have a graph of reactor temperature against time and I am trying to find the time the reactor temperature is at 455K.
To make this graph I used ode15 function [t,y] = ode15s(@(t,y)fun(t,y(1),y(2),y(3),y(4),y(5),y(6)), tspan, initial_conditions);
then plotted the graph using plot: figure(3) plot(t,T_2)
Does anyone know how to write code that would be able to find the time value?
I would appreciate any help, thanks.
  2 件のコメント
KSSV
KSSV 2022 年 1 月 17 日
How the plot is? How plot(t,T_2) looks?
Tom Goodland
Tom Goodland 2022 年 1 月 17 日

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

回答 (2 件)

KSSV
KSSV 2022 年 1 月 17 日
編集済み: KSSV 2022 年 1 月 17 日
idx = knnsearch(T_2,455) ;
t(idx)
If there is one-to-one mapping between (t,T_2)
iwant = interp1(T_2,t,455)
  4 件のコメント
KSSV
KSSV 2022 年 1 月 17 日
Try interp1 again.
Tom Goodland
Tom Goodland 2022 年 1 月 17 日
I used it again for the concentration plot, it worked the first time I did it with Ca, however when I tried to use it cb, cs and cd I got some errors, could this be due to the one-on-one mapping you mentioned?
plot(t,[ca,cb,cs,cd])
idx = knnsearch(0.9378,ca) ;
t(idx)
iwant = interp1(ca,t,0.9378);% ca = 1.1587
idx = knnsearch(0.9378,cb) ;
t(idx)
iwant = interp1(cb,t,0.9378);
idx = knnsearch(0.9378,cs) ;
t(idx)
iwant = interp1(cs,t,0.9378);
idx = knnsearch(0.9378,cd) ;
t(idx)
iwant = interp1(cd,t,0.9378);
The errors I got were:
Error using matlab.internal.math.interp1
Sample points must be unique.
Error in interp1 (line 188)
VqLite = matlab.internal.math.interp1(X,V,method,method,Xqcol);
Error in Twob (line 21)
iwant = interp1(cb,t,0.9378);

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


Star Strider
Star Strider 2022 年 1 月 17 日
I will re-post my original Answer because I believe it addresses the problem (although without the data, it is difficult to determine that with certainty) —
t = linspace(0, 10);
y = sin(2*pi*t/3) + t/10;
yval = 1;
idx = find(diff(sign(y-yval))); % Approximate Index Values For 'yval'
for k = 1:numel(idx)
idxrng = [max([1 idx(k)-2]) : min([numel(t) idx(k)+2])]; % Index Range For Interpolation
tval(k) = interp1(y(idxrng), t(idxrng), yval); % Interpolate
end
tval
tval = 1×7
0.5893 0.9546 3.3487 4.2029 6.1877 7.3731 9.0459
figure
plot(t,y)
hold on
plot(tval, ones(size(tval))*yval, '+r', 'MarkerSize',7.5)
hold off
grid
.
  8 件のコメント
Tom Goodland
Tom Goodland 2022 年 1 月 17 日
Thorsten I was looking at the ode event page on matlab last night and got quite confused, could you help define this event when T = 455 K please?

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

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by