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

3 次查看(过去 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 中查找有关 Interpolation of 2-D Selections in 3-D Grids 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by