Interpolating X axis values using a Y axis value and interp1 command.

조회 수: 5 (최근 30일)
% I need to interpolate this data using the interp1 command and find the X
% value (time) when the Y value is 105. I do not know how to
% reverse-interpolate this data to find the X value?
Ti=[0 1 2 3 4 5 6 7 8 9 10];
Temp=[72.5 78.1 86.4 92.3 110.6 111.5 109.3 110.2 110.5 109.9 110.2];
y=interp1(Ti,Temp,105,'pchip')
n=interp1(Temp,Ti,105,'pchip')
% I tried to reverse the axises in order to find the time value using an
% interp1 command, however it dosent work either? I have been told to use
% an fzero command however I am unsure of how to apply it?
  댓글 수: 1
Stephen23
Stephen23 2021년 7월 17일
"I tried to reverse the axises in order to find the time value using an interp1 command, however it dosent work either"
Lets first have a look at your data:
Ti = [0,1,2,3,4,5,6,7,8,9,10];
Temp = [72.5,78.1,86.4,92.3,110.6,111.5,109.3,110.2,110.5,109.9,110.2];
plot(Ti,Temp)
Now answer this very simple question: what is the expected Ti value for Temp==110 ?

댓글을 달려면 로그인하십시오.

채택된 답변

Image Analyst
Image Analyst 2021년 7월 17일
Try this:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format short g;
format compact;
fontSize = 15;
fprintf('Beginning to run %s.m ...\n', mfilename);
Ti=[0 1 2 3 4 5 6 7 8 9 10];
Temp=[72.5 78.1 86.4 92.3 110.6 111.5 109.3 110.2 110.5 109.9 110.2];
plot(Ti, Temp, 'b.', 'MarkerSize', 50);
xlabel('Ti', 'FontSize', fontSize);
ylabel('Temp', 'FontSize', fontSize);
xFit = linspace(min(Ti), max(Ti), 30000);
yFit = interp1(Ti, Temp, xFit, 'pchip');
hold on;
darkGreen = [0, 0.5, 0];
plot(xFit, yFit, '-', 'Color', darkGreen, 'LineWidth', 2);
index = find(yFit >= 105, 1, 'first')
x = xFit(index);
xline(x, 'Color', 'r', 'LineWidth', 2);
yline(105, 'Color', 'r', 'LineWidth', 2);
grid on;
str = sprintf('Ti = %.3f when Temp = %.2f', xFit(index), yFit(index));
title(str, 'FontSize', fontSize);

추가 답변 (1개)

Torsten
Torsten 2021년 7월 17일
f = @(x) (interp1(Ti,Temp,x,'pchip') - 105);
x0 = 3;
Ti105 = fzero(f,x0)

카테고리

Help CenterFile Exchange에서 Live Scripts and Functions에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by