Problem with interpolating missing data

Hi all, I have the following data:
d=[1:13]'
T_Req3 = [
26 24.6
27.3 26.4
19.3 16.1
24.3 23.3
25.1 21.2
26.2 25.6
29.7 28.7
32.7 30.9
28.5 27.3
30.5 30.3
NAN 33.3
35.5 35.2
26.1 25.4];
I need to find the value of NaN using interpolation. I tried the following code but didn't work: Any help would be highly appreciated. Thank you
Tl1 = T_Req3;
%Using the"find" function to filter the the NAN data
f = find(~isnan(T_Req3(11,:)));
% 4- Using the interpolation function to estimate the value of Tmax29
Tl1(11,1) = interp1(d(f),T_Req3(11,f),1);

 採用された回答

Star Strider
Star Strider 2018 年 10 月 4 日

1 投票

Try this:
d_T_Req3 = cat(2, d, T_Req3); % Concatenate
idx = ~any(isnan(d_T_Req3), 2); % Logical Index Of Rows Without ‘NaN’
T_new = interp1(d_T_Req3(idx,1), d_T_Req3(idx,2:end), d) % Interpolate
T_new =
26 24.6
27.3 26.4
19.3 16.1
24.3 23.3
25.1 21.2
26.2 25.6
29.7 28.7
32.7 30.9
28.5 27.3
30.5 30.3
33 32.75
35.5 35.2
26.1 25.4

2 件のコメント

D.J
D.J 2018 年 10 月 4 日
This is actually a much better answer as it shows both columns,, while the solution provided before displays only one column.
Thank you Star ! much appreciated
Star Strider
Star Strider 2018 年 10 月 4 日
As always, my pleasure!

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

その他の回答 (1 件)

Kevin Chng
Kevin Chng 2018 年 10 月 4 日
編集済み: Kevin Chng 2018 年 10 月 4 日

0 投票

Hi D J,
Hope my code could help you.
T_Req3 = [
26 24.6
27.3 26.4
19.3 16.1
24.3 23.3
25.1 21.2
26.2 25.6
29.7 28.7
32.7 30.9
28.5 27.3
30.5 30.3
NAN 33.3
35.5 35.2
26.1 25.4];
[TF,F] = fillmissing(T_Req3,'linear')
The missing data will be replaced in TF by linear method (Interpolation). F is telling you where is the missing data.
^^
if you want to know what is the filled value for your missing data
TF(F)

4 件のコメント

D.J
D.J 2018 年 10 月 4 日
Hi Kevin, thank you for your help, but I am required to use Interpolation, in particular the function "interp1" which is not used in your code, I am afraid.
Kevin Chng
Kevin Chng 2018 年 10 月 4 日
編集済み: Kevin Chng 2018 年 10 月 4 日
no worries, answer is same.
d=[1:13 ]';
T_Req3 = [
26 24.6
27.3 26.4
19.3 16.1
24.3 23.3
25.1 21.2
26.2 25.6
29.7 28.7
32.7 30.9
28.5 27.3
30.5 30.3
nan 33.3
35.5 35.2
26.1 25.4];
%Using the"find" function to filter the the NAN data
f=~isnan(T_Req3);
% 4- Using the interpolation function to estimate the value of Tmax29
NewT_Req3 = interp1(d(f(:,1)),T_Req3(f(:,1)),d)
D.J
D.J 2018 年 10 月 4 日
編集済み: D.J 2018 年 10 月 4 日
Thank you Kevin
Kevin Chng
Kevin Chng 2018 年 10 月 4 日
^^

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

カテゴリ

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

タグ

質問済み:

D.J
2018 年 10 月 4 日

コメント済み:

2018 年 10 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by