I need to use MATLAB to interpolate this weather data Weathe

I need to use MATLAB to interpolate this weather data.

Weather

Column 1(month) Column 2( temp 0C)

This is the MATLAB script I wrote but it is not working

clc;
clear;
format compact;

M = [ 1 3 6 9 12 15 18 21 24 27 30 33 36 39 42 42 48];
T = [ 5 10 20 13 7 12 22 10 10 15 26 20 6 13 25 18 10];

x = 1:1:48;
y =interp1(M,T,x,\'spline\');
plot(M,T,\'o\',x,y),title(\'Temperature vs. Month\'),...
xlable(\'Month\'),ylable(\'Temperature, degrees C\'),
set(gca,\'XMinorTick\',\'on\', \'YMinorTick\',\'on\')

Can someone please help

1 5
3 10
6 20
9 13
12 7
15 12
18 22
21 10
24 10
27 15
30 26
33 20
36 6
39 13
42 25
45 18
48 10

Solution

The below code works,the error is in M vector 42 is repeated but in table it is 42 45 48 ,I have changed that you can observe it,now the code is working

M = [ 1 3 6 9 12 15 18 21 24 27 30 33 36 39 42 45 48];

T = [ 5 10 20 13 7 12 22 10 10 15 26 20 6 13 25 18 10];

x = 1:1:48;
y =interp1(M,T,x,\'spline\');
plot(M,T,\'o\',x,y),title(\'Temperature vs. Month\'),...
xlable(\'Month\'),ylable(\'Temperature, degrees C\'),
set(gca,\'XMinorTick\',\'on\', \'YMinorTick\',\'on\')

I need to use MATLAB to interpolate this weather data. Weather Column 1(month) Column 2( temp 0C) This is the MATLAB script I wrote but it is not working clc; c

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site