%% In a laboratory experiment, data of voltage and current has been recorded and the same is attached in an excel file ( 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. Additionally,
% compute the current values for given voltages below and store them in a text file.
%% 1) Read the excel file in the Matlab program and perform the interpolation in the range of -17.3:0.1:0.9
sheet=1;
Voltage = 'A2:A25';
Current= 'B2:B25';
V = xlsread('VI.xlsx',sheet,Voltage);
A = xlsread('VI.xlsx',sheet,Current);
B= [-17.3:0.1:0.9];
AB= interp1(V,A,B,'linear');
XY= interp1(V,A,B,'spline');
%% 2) Generate the interactive plot for the interpolated data
figure(1);
plot(V,A','o',B,AB,':.');grid; title('Voltage vs Current (linear interpolation)');
xlabel('Voltage');ylabel('Current');
figure(2);
plot(V,A','o',B,XY,':.');grid; title('Voltage vs Current (spline interpolation)');
xlabel('Voltage');ylabel('Current');
%% 3) compute the current values for given voltages below and store them in a text file
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]';
P = interp1(V,A,VV);
Z=[VV P];
fileID = fopen('Missing Data .txt','w');
fprintf(fileID,'%6s %12s\n','VV','P');
fprintf(fileID,'%6.2s %12.8f\n',Z);
fclose(fileID);