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

3 ビュー (過去 30 日間)
Petch Anuwutthinawin
Petch Anuwutthinawin 2021 年 7 月 17 日
コメント済み: Stephen23 2021 年 7 月 17 日
% 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 Center および File ExchangeInterpolation 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