Trying to find an x value from a certain y value on my graph
75 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (2 件)
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
figure
plot(t,y)
hold on
plot(tval, ones(size(tval))*yval, '+r', 'MarkerSize',7.5)
hold off
grid
.
8 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!