Project - Data Handling and Interpolation
Q1:-In a laboratory experiment, data of voltage and current has been recorded and the same is attached in an excel file ( Click on this link VI.xlsx ). Read the excel file in the Matlab program and perform the interpolation in the range of -17.3:0.1:0.9. Generate the interactive plot for the interpolated data and store them in a text file.
solution:-
close
clear
clc
data=readmatrix("VI.xlsx");
%readmatrix helps to read the matrix in the file
v=data(:,1);%v as V (Volt)
i=data(:,2);%i as mAmp
r=-17.3:0.1:0.9;%r as interpolation in the range
int_1=interp1(v,i,r);%interpolation with linear method
int_2=interp1(v,i,r,"spline");%interpolation with spline method
figure(1)
plot(v,i,'r',r,int_1,'b.');grid;
%plot is used to plot 2d line,grid to add grid in plot
legend('Original','Linear Interpolation');
%legend is used to add legend to axes
title('Linear Interpolation')
%title to add title for the plot
xlabel('Temperature');ylabel('Altitude')
%xlabel to name axis ylabel to name yaxis
figure(2)
plot(v,i,'r',r,int_2,'b.');grid;
%plot is used to plot 2d line,grid to add grid in plot
legend('Original','Spline Interpolation');
%legend is used to add legend to axes
title('Spline Interpolation');
%title to add title for the plot
xlabel('Temperature');ylabel('Altitude');
%xlabel to name axis ylabel to name yaxis
data_of_interpolation=[r' int_2' int_2'];
writematrix(data_of_interpolation,'interpolation data.txt')



output of interpolation in txt file:-
-17.3,-28,-28
-17.2,-28.1734256447144,-28.1734256447144
-17.1,-24,-24
-17,-19,-19
-16.9,-15.8685294950185,-15.8685294950185
-16.8,-14,-14
-16.7,-12.2353372836135,-12.2353372836135
-16.6,-10.5022164647839,-10.5022164647839
-16.5,-9,-9
-16.4,-7.88060899403963,-7.88060899403963
-16.3,-7.10619914483659,-7.10619914483659
-16.2,-6.59148479861374,-6.59148479861374
-16.1,-6.25118030159395,-6.25118030159395
-16,-6,-6
-15.9,-5.76703105615325,-5.76703105615325
-15.8,-5.53885189676899,-5.53885189676899
-15.7,-5.31641376466102,-5.31641376466102
-15.6,-5.10066790264313,-5.10066790264313
-15.5,-4.89256555352912,-4.89256555352912
-15.4,-4.69305796013278,-4.69305796013278
-15.3,-4.5030963652679,-4.5030963652679
-15.2,-4.32363201174828,-4.32363201174828
-15.1,-4.15561614238772,-4.15561614238772
-15,-4,-4
-14.9,-3.85739973042026,-3.85739973042026
-14.8,-3.72709109156898,-3.72709109156898
-14.7,-3.60801474438795,-3.60801474438795
-14.6,-3.499111349819,-3.499111349819
-14.5,-3.39932156880392,-3.39932156880392
-14.4,-3.30758606228453,-3.30758606228453
-14.3,-3.22284549120263,-3.22284549120263
-14.2,-3.14404051650004,-3.14404051650004
-14.1,-3.07011179911856,-3.07011179911856
-14,-3,-3
-13.9,-2.93279978824827,-2.93279978824827
-13.8,-2.86822186561566,-2.86822186561566
-13.7,-2.80613094201655,-2.80613094201655
-13.6,-2.74639172736534,-2.74639172736534
-13.5,-2.6888689315764,-2.6888689315764
-13.4,-2.63342726456414,-2.63342726456414
-13.3,-2.57993143624294,-2.57993143624294
-13.2,-2.52824615652718,-2.52824615652718
-13.1,-2.47823613533125,-2.47823613533125
-13,-2.42976608256955,-2.42976608256955
-12.9,-2.38270070815645,-2.38270070815645
-12.8,-2.33690472200636,-2.33690472200636
-12.7,-2.29224283403364,-2.29224283403364
-12.6,-2.2485797541527,-2.2485797541527
-12.5,-2.20578019227792,-2.20578019227792
-12.4,-2.16370885832369,-2.16370885832369
-12.3,-2.12223046220439,-2.12223046220439
-12.2,-2.08120971383442,-2.08120971383442
-12.1,-2.04051132312816,-2.04051132312816
-12,-2,-2
-11.9,-1.9595753654897,-1.9595753654897
-11.8,-1.91927668513854,-1.91927668513854
-11.7,-1.87917813561314,-1.87917813561314
-11.6,-1.83935389358016,-1.83935389358016
-11.5,-1.79987813570623,-1.79987813570623
-11.4,-1.76082503865799,-1.76082503865799
-11.3,-1.72226877910209,-1.72226877910209
-11.2,-1.68428353370518,-1.68428353370518
-11.1,-1.64694347913388,-1.64694347913388
-11,-1.61032279205484,-1.61032279205484
-10.9,-1.57449564913471,-1.57449564913471
-10.8,-1.53953622704012,-1.53953622704012
-10.7,-1.50551870243771,-1.50551870243771
-10.6,-1.47251725199414,-1.47251725199414
-10.5,-1.44060605237603,-1.44060605237603
-10.4,-1.40985928025004,-1.40985928025004
-10.3,-1.3803511122828,-1.3803511122828
-10.2,-1.35215572514095,-1.35215572514095
-10.1,-1.32534729549114,-1.32534729549114
-10,-1.3,-1.3
-9.9,-1.27616124979292,-1.27616124979292
-9.8,-1.2537713938302,-1.2537713938302
-9.7,-1.23274401553089,-1.23274401553089
-9.6,-1.21299269831404,-1.21299269831404
-9.5,-1.19443102559869,-1.19443102559869
-9.4,-1.17697258080389,-1.17697258080389
-9.3,-1.16053094734868,-1.16053094734868
-9.2,-1.14501970865212,-1.14501970865212
-9.1,-1.13035244813324,-1.13035244813324
-9,-1.11644274921109,-1.11644274921109
-8.9,-1.10320419530472,-1.10320419530472
-8.8,-1.09055036983318,-1.09055036983318
-8.7,-1.0783948562155,-1.0783948562155
-8.6,-1.06665123787074,-1.06665123787074
-8.5,-1.05523309821794,-1.05523309821794
-8.4,-1.04405402067616,-1.04405402067616
-8.3,-1.03302758866442,-1.03302758866442
-8.2,-1.02206738560179,-1.02206738560179
-8.1,-1.0110869949073,-1.0110869949073
-8,-1,-1
-7.9,-0.988735199374782,-0.988735199374782
-7.8,-0.977282251829893,-0.977282251829893
-7.7,-0.965646031239426,-0.965646031239426
-7.6,-0.953831411477472,-0.953831411477472
-7.5,-0.941843266418124,-0.941843266418124
-7.4,-0.929686469935473,-0.929686469935473
-7.3,-0.917365895903612,-0.917365895903612
-7.2,-0.904886418196631,-0.904886418196631
-7.1,-0.892252910688623,-0.892252910688623
-7,-0.879470247253681,-0.879470247253681
-6.9,-0.866543301765895,-0.866543301765895
-6.8,-0.853476948099358,-0.853476948099358
-6.7,-0.840276060128162,-0.840276060128162
-6.6,-0.826945511726398,-0.826945511726398
-6.5,-0.813490176768159,-0.813490176768159
-6.4,-0.799914929127536,-0.799914929127536
-6.3,-0.786224642678622,-0.786224642678622
-6.2,-0.772424191295507,-0.772424191295507
-6.1,-0.758518448852285,-0.758518448852285
-6,-0.744512289223046,-0.744512289223046
-5.9,-0.730410586281884,-0.730410586281884
-5.8,-0.716218213902889,-0.716218213902889
-5.7,-0.701940045960154,-0.701940045960154
-5.6,-0.687580956327771,-0.687580956327771
-5.5,-0.673145818879831,-0.673145818879831
-5.4,-0.658639507490426,-0.658639507490426
-5.3,-0.644066896033649,-0.644066896033649
-5.2,-0.629432858383591,-0.629432858383591
-5.1,-0.614742268414344,-0.614742268414344
-5,-0.6,-0.6
-4.9,-0.585216190870722,-0.585216190870722
-4.8,-0.570422034180953,-0.570422034180953
-4.7,-0.55565398694121,-0.55565398694121
-4.6,-0.540948506162007,-0.540948506162007
-4.5,-0.52634204885386,-0.52634204885386
-4.4,-0.511871072027283,-0.511871072027283
-4.3,-0.497572032692792,-0.497572032692792
-4.2,-0.483481387860902,-0.483481387860902
-4.1,-0.469635594542128,-0.469635594542128
-4,-0.456071109746986,-0.456071109746986
-3.9,-0.442824390485989,-0.442824390485989
-3.8,-0.429931893769654,-0.429931893769654
-3.7,-0.417430076608496,-0.417430076608496
-3.6,-0.405355396013029,-0.405355396013029
-3.5,-0.39374430899377,-0.39374430899377
-3.4,-0.382633272561232,-0.382633272561232
-3.3,-0.372058743725932,-0.372058743725932
-3.2,-0.362057179498384,-0.362057179498384
-3.1,-0.352665036889103,-0.352665036889103
-3,-0.343918772908605,-0.343918772908605
-2.9,-0.335854844567405,-0.335854844567405
-2.8,-0.328509708876017,-0.328509708876017
-2.7,-0.321919822844958,-0.321919822844958
-2.6,-0.316121643484742,-0.316121643484742
-2.5,-0.311151627805884,-0.311151627805884
-2.4,-0.3070462328189,-0.3070462328189
-2.3,-0.303841915534304,-0.303841915534304
-2.2,-0.301575132962612,-0.301575132962612
-2.1,-0.300282342114339,-0.300282342114339
-2,-0.3,-0.3
-1.9,-0.300694387778356,-0.300694387778356
-1.8,-0.302051083201149,-0.302051083201149
-1.7,-0.303685488168369,-0.303685488168369
-1.6,-0.305213004580003,-0.305213004580003
-1.5,-0.30624903433604,-0.30624903433604
-1.4,-0.30640897933647,-0.30640897933647
-1.3,-0.305308241481279,-0.305308241481279
-1.2,-0.302562222670458,-0.302562222670458
-1.1,-0.297786324803993,-0.297786324803993
-1,-0.290595949781875,-0.290595949781875
-0.9,-0.280606499504091,-0.280606499504091
-0.8,-0.26743337587063,-0.26743337587063
-0.7,-0.25069198078148,-0.25069198078148
-0.6,-0.22999771613663,-0.22999771613663
-0.5,-0.204965983836069,-0.204965983836069
-0.4,-0.175212185779784,-0.175212185779784
-0.3,-0.140351723867765,-0.140351723867765
-0.2,-0.1,-0.1
-0.1,-0.0558891664937565,-0.0558891664937565
0,-0.0182183773354182,-0.0182183773354182
0.1,0.000704958683086859,0.000704958683086859
0.2,-0.000161665906564869,-0.000161665906564869
0.3,0.000228251413584533,0.000228251413584533
0.4,0.0128524579834356,0.0128524579834356
0.5,0.17,0.17
0.6,1.23,1.23
0.7,10.0433375615302,10.0433375615302
0.8,39.0700570806576,39.0700570806576
0.9,101.110221980335,101.110221980335
codes used in the project:-
- close:-close command helps to close one or more figures
-
clear:-clear command helps to clear the data or item in the work space
-
clc:-clc command helps to clear the data or item in command windows
- readmatrix:-readmatrix helps to read the matrix from the file
- interp1:-interp1 helps in interpolation of 1d data
- plot:-plot command is used to draw 2d line plot
- grid:-grid command is used to add grid in the plot
- xlabel:-xlabel command is used to label the Xaxis
- ylabel:-ylabel command is used to label the Yaxis
- title:-title command is used to name the title of the plot
- legend:-legend command is used to add legend to the axes
- writematrix:-write matrix helps to write a matrix in a file
- figure:-figure helps to create a single or multiple figure window