Simple Linear Interpolation using Interp1

Hi all. I'm fairly new to Matlab and I'm just trying to interpolate.
I have a [1 12] time vector that represent 12 hours. I also have a temperature vector that only has 10 values because 2 of them are missing. I understand that the sizes must be equal to use interp1. This is what I have so far:
time = [1 2 3 4 5 6 7 8 9 10 11 12];
temp = [10 12 15 13 [] 16 16 18 [] 15 21 20];
points = [1 2 3 4 5 6 7 8 9 10 11 12];
y = interp1(time,temp,points,'linear')
The empty matrices are where I don't have available times. I'm trying to use all of this data to linearly interpolate temperatures for all entries in my points array.
Thanks so much :)

 採用された回答

Andrei Bobrov
Andrei Bobrov 2014 年 8 月 14 日
編集済み: Andrei Bobrov 2014 年 8 月 14 日

2 投票

time = [1 2 3 4 6 7 8 10 11 12];
temp = [10 12 15 13 16 16 18 15 21 20];
points = [1 2 3 4 5 6 7 8 9 10 11 12];
y = interp1(time,temp,points,'linear');

5 件のコメント

Michael
Michael 2014 年 8 月 14 日
Wow. Thank you.
Ammar Anayi
Ammar Anayi 2021 年 10 月 14 日
Hello Sir, if I had the temperatures but not the time. What should i do, how would the code look like.
Thanks!
Leon
Leon 2022 年 1 月 4 日
That's a very neat solution. I wonder if you know how to display the slope and intercept values?
Gem
Gem 2022 年 11 月 19 日
May I have a question, is it possible to interpolate the data (NaN) if the x and y does have the same length in 3D plot.
Thank you !
Peter
Peter 2024 年 4 月 23 日
Thank you from 10 years later!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeInterpolation についてさらに検索

質問済み:

2014 年 8 月 14 日

コメント済み:

2024 年 4 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by