Interpolating X axis values using a Y axis value and interp1 command.
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Petch Anuwutthinawin
il 17 Lug 2021
Commentato: Stephen23
il 17 Lug 2021
% 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 Commento
Stephen23
il 17 Lug 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 ?
Risposta accettata
Image Analyst
il 17 Lug 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);
0 Commenti
Più risposte (1)
Torsten
il 17 Lug 2021
f = @(x) (interp1(Ti,Temp,x,'pchip') - 105);
x0 = 3;
Ti105 = fzero(f,x0)
0 Commenti
Vedere anche
Categorie
Scopri di più su Interpolation of 2-D Selections in 3-D Grids in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!