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

11 Ansichten (letzte 30 Tage)
% 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 Kommentar
Stephen23
Stephen23 am 17 Jul. 2021
"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 ?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Image Analyst
Image Analyst am 17 Jul. 2021
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);

Weitere Antworten (1)

Torsten
Torsten am 17 Jul. 2021
f = @(x) (interp1(Ti,Temp,x,'pchip') - 105);
x0 = 3;
Ti105 = fzero(f,x0)

Kategorien

Mehr zu Live Scripts and Functions finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by