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.
STUDY: Given Data in excel file:
|
V (Volt) |
I (mAmp) |
|
-17.3 |
-28 |
|
-17.1 |
-24 |
|
-17 |
-19 |
|
-16.8 |
-14 |
|
-16.5 |
-9 |
|
-16 |
-6 |
|
-15 |
-4 |
|
-14 |
-3 |
|
-12 |
-2 |
|
-10 |
-1.3 |
|
-8 |
-1 |
|
-5 |
-0.6 |
|
-2 |
-0.3 |
|
-0.2 |
-0.1 |
|
0.09 |
0 |
|
0.19 |
0 |
|
0.27 |
0 |
|
0.39 |
0.01 |
|
0.43 |
0.03 |
|
0.5 |
0.17 |
|
0.55 |
0.42 |
|
0.6 |
1.23 |
|
0.62 |
1.99 |
|
0.65 |
3.91 |
Reading the spreadsheet file in MatLab
>> VI=xlsread('VI.xlsx')
VI =
-17.3000 -28.0000
-17.1000 -24.0000
-17.0000 -19.0000
-16.8000 -14.0000
-16.5000 -9.0000
-16.0000 -6.0000
-15.0000 -4.0000
-14.0000 -3.0000
-12.0000 -2.0000
-10.0000 -1.3000
-8.0000 -1.0000
-5.0000 -0.6000
-2.0000 -0.3000
-0.2000 -0.1000
0.0900 0
0.1900 0
0.2700 0
0.3900 0.0100
0.4300 0.0300
0.5000 0.1700
0.5500 0.4200
0.6000 1.2300
0.6200 1.9900
0.6500 3.9100
Giving names and saving Datas as first column Voltage and second column as Amps
>> Voltage=VI(:,1);
>> Amps=VI(:,2);
Applying range
>> range=-17.3:0.1:0.9;
Applying interplation1 to get 2D Image
>> yq1=interp1(Voltage,Amps,range);
Plotting VI graph and applying values
>> figure(1);plot(Voltage, Amps,'*');grid;
>> title('V vs I');
>> ylabel('I(mAmps)');
>> xlabel('V(volt)');
Saving figure1 as pdf
>> print('V vs I','-dpdf');
Plotting range vs interpolation1 graph and applying values
>> figure(2);plot(range,yq1,'*');grid;
>> title('Range vs Interpolation1');
>> ylabel('I(mAmps)');
>> xlabel('V(volt)');
Saving figure2 as pdf
>> print('Range vs Interpolation','-dpdf');
Plotting Fig1 & Fig2 summation graph and applying values
>> figure(3);plot(Voltage, Amps,'*',range,yq1);grid;
>> title('Fig1 & Fig2 summation');
>> ylabel('I(mAmps)');
>> xlabel('V(volt)');
Saving figure3 as pdf
>> print('Fig1 & Fig2 summation','-dpdf');
Data Given
>> VV=[-17.2 -17.1 -13.8 -13.5 -13.0 -12.5 -11 -9 -5.76 -6 -1 0.11 0.25 0.5 0.61]
VV =
Columns 1 through 5
-17.2000 -17.1000 -13.8000 -13.5000 -13.0000
Columns 6 through 10
-12.5000 -11.0000 -9.0000 -5.7600 -6.0000
Columns 11 through 15
-1.0000 0.1100 0.2500 0.5000 0.6100
>> legend('VI data','VI interpolated data');
Applying Spline Interpolation
>> yq2=interp1(Voltage,Amps,VV,'spline');
Plotting Given Data (VV) vs Interpolated Data graph and applying values
>> figure(4);plot(VV,yq2,'*',range,yq1);grid;
>> title('VV vs VI');
>> ylabel('I(mAmps)');
>> xlabel('V(volt)');
>> title('Given Data VV vs Interpolated Data');
>> legend('Given data','Interpolated data');
Saving figure4 as pdf
>> print('Given Data VV vs Interpolated Data','-dpdf');
Savng the values into a text file
File opening
>> fid=fopen('VI.txt','w');
Giving Headings as Volt and Amps
>> fprintf(fid,'V(Volt) I(Amps)\n');
>> len=length(VV);
\n for next line,%f is used instead of %d to get decimal values
>> for i=1:len, fprintf(fid,'%f %f\n',VV(i),yq2(i));
end;
File closing
>> fclose(fid);
Given VV is denoted as Volt
V(Volt) I(Amps)
-17.20000 -28.173426
-17.10000 -24.000000
-13.80000 -2.868222
-13.50000 -2.688869
-13.00000 -2.429766
-12.50000 -2.205780
-11.00000 -1.610323
-9.000000 -1.116443
-5.760000 -0.710517
-6.000000 -0.744512
-1.000000 -0.290596
0.110000 0.001150
0.250000 -0.000137
0.500000 0.170000
0.610000 1.566533