Trying to find an x value from a certain y value on my graph
조회 수: 32 (최근 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
.
참고 항목
카테고리
Help Center 및 File Exchange에서 Line Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!