Project - Data Handling and Interpolation
Project- 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.?
Ans -
reading= xlsread("vi.xlsx"); % xlsread command is used to read the excel file contain data of voltage and current and stored in variable name reading
v=reading(:,1) % all values of voltage read from reading variable means all rows and first column
i=reading(:,2) % all values of current read from reading variable means all rows and second column
x=-17.3:0.1:0.9; % this is actually the range given in project used for interpolation
subplot(311) % this command indicates position & 2 rows and 1 columns in matrix
plot(v,i,'r+') % This is a plot between voltage & current and 'plus' sign indicated with red colour means it shows reading point mentioned in question
legend('reading given') % this is a command used to clearly visualize the data in graph
title("reading points given in question") % this is a topic or heading given for plot to clearly specify things.
y=interp1(v,i,x);% this is a command used to identify unknown points on a plot
subplot(312) % this command place the graph at second position in 2 rows and 1 column matrix
plot(x,y,'g--') % this command is used to plot the graph by identifying the known points using interpolation
title('points analyzed using interpolation') % it is used to give topic or heading to the plot
legend('unknown reading points')% it gives clarity by indicating data points
y1=interp1(v,i,x,'spline') % command used to identify points at unknown location
subplot(313) % it is a command used to give position to graph in matrix
plot(x,y1,'b-') % it is a command used to plot a graph
title('spline graph') % it simply used to title the graph
legend('points analyzed using interpolation by spline') % it helps in clear visualization
figure(2) % it is simply the title
plot(v,i,'*r',x,y,'g--'); %it generates the plot indicating identified and unidentified points
title('complete curve after using interpolation') % this is simply a heading on graph
legend('given reading points','unknown reading points') % this is used visualise a graph in crystal clear manner.
figure(3) % it simply label the graph
plot(v,i,'r',x,y1,'g*') % this command is used to plot the 2D graph.
title('interpolation points using spline') % it is a heading on graph
legend('given reading points','unknown points')% it help in visualizing the graph
fid = fopen('vi-reading.txt', 'w') % file pointer variable is created and fopen command is used to load data in text file
fprintf(fid,"%8s %10s\n",'volt','amp') %
fprintf(fid,'%f %f\n',y,y1); % it helps to display the floating values
fclose(fid); % it is used to closed the file
Output - 
Figure-2 :- 
Figure -3 :- 
Output-
[x;y]
ans =
Columns 1 through 12
-17.3000 -17.2000 -17.1000 -17.0000 -16.9000 -16.8000 -16.7000 -16.6000 -16.5000 -16.4000 -16.3000 -16.2000
-28.0000 -26.0000 -24.0000 -19.0000 -16.5000 -14.0000 -12.3333 -10.6667 -9.0000 -8.4000 -7.8000 -7.2000
Columns 13 through 24
-16.1000 -16.0000 -15.9000 -15.8000 -15.7000 -15.6000 -15.5000 -15.4000 -15.3000 -15.2000 -15.1000 -15.0000
-6.6000 -6.0000 -5.8000 -5.6000 -5.4000 -5.2000 -5.0000 -4.8000 -4.6000 -4.4000 -4.2000 -4.0000
Columns 25 through 36
-14.9000 -14.8000 -14.7000 -14.6000 -14.5000 -14.4000 -14.3000 -14.2000 -14.1000 -14.0000 -13.9000 -13.8000
-3.9000 -3.8000 -3.7000 -3.6000 -3.5000 -3.4000 -3.3000 -3.2000 -3.1000 -3.0000 -2.9500 -2.9000
Columns 37 through 48
-13.7000 -13.6000 -13.5000 -13.4000 -13.3000 -13.2000 -13.1000 -13.0000 -12.9000 -12.8000 -12.7000 -12.6000
-2.8500 -2.8000 -2.7500 -2.7000 -2.6500 -2.6000 -2.5500 -2.5000 -2.4500 -2.4000 -2.3500 -2.3000
Columns 49 through 60
-12.5000 -12.4000 -12.3000 -12.2000 -12.1000 -12.0000 -11.9000 -11.8000 -11.7000 -11.6000 -11.5000 -11.4000
-2.2500 -2.2000 -2.1500 -2.1000 -2.0500 -2.0000 -1.9650 -1.9300 -1.8950 -1.8600 -1.8250 -1.7900
Columns 61 through 72
-11.3000 -11.2000 -11.1000 -11.0000 -10.9000 -10.8000 -10.7000 -10.6000 -10.5000 -10.4000 -10.3000 -10.2000
-1.7550 -1.7200 -1.6850 -1.6500 -1.6150 -1.5800 -1.5450 -1.5100 -1.4750 -1.4400 -1.4050 -1.3700
Columns 73 through 84
-10.1000 -10.0000 -9.9000 -9.8000 -9.7000 -9.6000 -9.5000 -9.4000 -9.3000 -9.2000 -9.1000 -9.0000
-1.3350 -1.3000 -1.2850 -1.2700 -1.2550 -1.2400 -1.2250 -1.2100 -1.1950 -1.1800 -1.1650 -1.1500
Columns 85 through 96
-8.9000 -8.8000 -8.7000 -8.6000 -8.5000 -8.4000 -8.3000 -8.2000 -8.1000 -8.0000 -7.9000 -7.8000
-1.1350 -1.1200 -1.1050 -1.0900 -1.0750 -1.0600 -1.0450 -1.0300 -1.0150 -1.0000 -0.9867 -0.9733
Columns 97 through 108
-7.7000 -7.6000 -7.5000 -7.4000 -7.3000 -7.2000 -7.1000 -7.0000 -6.9000 -6.8000 -6.7000 -6.6000
-0.9600 -0.9467 -0.9333 -0.9200 -0.9067 -0.8933 -0.8800 -0.8667 -0.8533 -0.8400 -0.8267 -0.8133
Columns 109 through 120
-6.5000 -6.4000 -6.3000 -6.2000 -6.1000 -6.0000 -5.9000 -5.8000 -5.7000 -5.6000 -5.5000 -5.4000
-0.8000 -0.7867 -0.7733 -0.7600 -0.7467 -0.7333 -0.7200 -0.7067 -0.6933 -0.6800 -0.6667 -0.6533
Columns 121 through 132
-5.3000 -5.2000 -5.1000 -5.0000 -4.9000 -4.8000 -4.7000 -4.6000 -4.5000 -4.4000 -4.3000 -4.2000
-0.6400 -0.6267 -0.6133 -0.6000 -0.5900 -0.5800 -0.5700 -0.5600 -0.5500 -0.5400 -0.5300 -0.5200
Columns 133 through 144
-4.1000 -4.0000 -3.9000 -3.8000 -3.7000 -3.6000 -3.5000 -3.4000 -3.3000 -3.2000 -3.1000 -3.0000
-0.5100 -0.5000 -0.4900 -0.4800 -0.4700 -0.4600 -0.4500 -0.4400 -0.4300 -0.4200 -0.4100 -0.4000
Columns 145 through 156
-2.9000 -2.8000 -2.7000 -2.6000 -2.5000 -2.4000 -2.3000 -2.2000 -2.1000 -2.0000 -1.9000 -1.8000
-0.3900 -0.3800 -0.3700 -0.3600 -0.3500 -0.3400 -0.3300 -0.3200 -0.3100 -0.3000 -0.2889 -0.2778
Columns 157 through 168
-1.7000 -1.6000 -1.5000 -1.4000 -1.3000 -1.2000 -1.1000 -1.0000 -0.9000 -0.8000 -0.7000 -0.6000
-0.2667 -0.2556 -0.2444 -0.2333 -0.2222 -0.2111 -0.2000 -0.1889 -0.1778 -0.1667 -0.1556 -0.1444
Columns 169 through 180
-0.5000 -0.4000 -0.3000 -0.2000 -0.1000 0 0.1000 0.2000 0.3000 0.4000 0.5000 0.6000
-0.1333 -0.1222 -0.1111 -0.1000 -0.0655 -0.0310 0 0 0.0025 0.0150 0.1700 1.2300
Output -
[x;y1]
ans =
Columns 1 through 12
-17.3000 -17.2000 -17.1000 -17.0000 -16.9000 -16.8000 -16.7000 -16.6000 -16.5000 -16.4000 -16.3000 -16.2000
-28.0000 -28.1734 -24.0000 -19.0000 -15.8685 -14.0000 -12.2353 -10.5022 -9.0000 -7.8806 -7.1062 -6.5915
Columns 13 through 24
-16.1000 -16.0000 -15.9000 -15.8000 -15.7000 -15.6000 -15.5000 -15.4000 -15.3000 -15.2000 -15.1000 -15.0000
-6.2512 -6.0000 -5.7670 -5.5389 -5.3164 -5.1007 -4.8926 -4.6931 -4.5031 -4.3236 -4.1556 -4.0000
Columns 25 through 36
-14.9000 -14.8000 -14.7000 -14.6000 -14.5000 -14.4000 -14.3000 -14.2000 -14.1000 -14.0000 -13.9000 -13.8000
-3.8574 -3.7271 -3.6080 -3.4991 -3.3993 -3.3076 -3.2228 -3.1440 -3.0701 -3.0000 -2.9328 -2.8682
Columns 37 through 48
-13.7000 -13.6000 -13.5000 -13.4000 -13.3000 -13.2000 -13.1000 -13.0000 -12.9000 -12.8000 -12.7000 -12.6000
-2.8061 -2.7464 -2.6889 -2.6334 -2.5799 -2.5282 -2.4782 -2.4298 -2.3827 -2.3369 -2.2922 -2.2486
Columns 49 through 60
-12.5000 -12.4000 -12.3000 -12.2000 -12.1000 -12.0000 -11.9000 -11.8000 -11.7000 -11.6000 -11.5000 -11.4000
-2.2058 -2.1637 -2.1222 -2.0812 -2.0405 -2.0000 -1.9596 -1.9193 -1.8792 -1.8394 -1.7999 -1.7608
Columns 61 through 72
-11.3000 -11.2000 -11.1000 -11.0000 -10.9000 -10.8000 -10.7000 -10.6000 -10.5000 -10.4000 -10.3000 -10.2000
-1.7223 -1.6843 -1.6469 -1.6103 -1.5745 -1.5395 -1.5055 -1.4725 -1.4406 -1.4099 -1.3804 -1.3522
Columns 73 through 84
-10.1000 -10.0000 -9.9000 -9.8000 -9.7000 -9.6000 -9.5000 -9.4000 -9.3000 -9.2000 -9.1000 -9.0000
-1.3253 -1.3000 -1.2762 -1.2538 -1.2327 -1.2130 -1.1944 -1.1770 -1.1605 -1.1450 -1.1304 -1.1164
Columns 85 through 96
-8.9000 -8.8000 -8.7000 -8.6000 -8.5000 -8.4000 -8.3000 -8.2000 -8.1000 -8.0000 -7.9000 -7.8000
-1.1032 -1.0906 -1.0784 -1.0667 -1.0552 -1.0441 -1.0330 -1.0221 -1.0111 -1.0000 -0.9887 -0.9773
Columns 97 through 108
-7.7000 -7.6000 -7.5000 -7.4000 -7.3000 -7.2000 -7.1000 -7.0000 -6.9000 -6.8000 -6.7000 -6.6000
-0.9656 -0.9538 -0.9418 -0.9297 -0.9174 -0.9049 -0.8923 -0.8795 -0.8665 -0.8535 -0.8403 -0.8269
Columns 109 through 120
-6.5000 -6.4000 -6.3000 -6.2000 -6.1000 -6.0000 -5.9000 -5.8000 -5.7000 -5.6000 -5.5000 -5.4000
-0.8135 -0.7999 -0.7862 -0.7724 -0.7585 -0.7445 -0.7304 -0.7162 -0.7019 -0.6876 -0.6731 -0.6586
Columns 121 through 132
-5.3000 -5.2000 -5.1000 -5.0000 -4.9000 -4.8000 -4.7000 -4.6000 -4.5000 -4.4000 -4.3000 -4.2000
-0.6441 -0.6294 -0.6147 -0.6000 -0.5852 -0.5704 -0.5557 -0.5409 -0.5263 -0.5119 -0.4976 -0.4835
Columns 133 through 144
-4.1000 -4.0000 -3.9000 -3.8000 -3.7000 -3.6000 -3.5000 -3.4000 -3.3000 -3.2000 -3.1000 -3.0000
-0.4696 -0.4561 -0.4428 -0.4299 -0.4174 -0.4054 -0.3937 -0.3826 -0.3721 -0.3621 -0.3527 -0.3439
Columns 145 through 156
-2.9000 -2.8000 -2.7000 -2.6000 -2.5000 -2.4000 -2.3000 -2.2000 -2.1000 -2.0000 -1.9000 -1.8000
-0.3359 -0.3285 -0.3219 -0.3161 -0.3112 -0.3070 -0.3038 -0.3016 -0.3003 -0.3000 -0.3007 -0.3021
Columns 157 through 168
-1.7000 -1.6000 -1.5000 -1.4000 -1.3000 -1.2000 -1.1000 -1.0000 -0.9000 -0.8000 -0.7000 -0.6000
-0.3037 -0.3052 -0.3062 -0.3064 -0.3053 -0.3026 -0.2978 -0.2906 -0.2806 -0.2674 -0.2507 -0.2300
Columns 169 through 180
-0.5000 -0.4000 -0.3000 -0.2000 -0.1000 0 0.1000 0.2000 0.3000 0.4000 0.5000 0.6000
-0.2050 -0.1752 -0.1404 -0.1000 -0.0559 -0.0182 0.0007 -0.0002 0.0002 0.0129 0.1700 1.2300
Columns 181 through 183
0.7000 0.8000 0.9000
10.0433 39.0701 101.1102