Project - Data Handling and Interpolation
% Program reads data from excel sheet and executes interpolation for the given range of data
A= xlsread('VI.xlsx')
V= A(:,1); % Reading and storing the values of voltage in vector V.
I= A(:,2); % Reading and storing the values of current in vector I.
plot(V,I,'*'); % plotting V vs I
hold on;
Vx=-17.3:0.1:0.9; % interpolation range
Ix=spline(V,I,Vx);
plot(Vx,Ix,'-g'); % plotting interpolated Vx Vs Ix curve.
grid;
xlabel(' Voltage V'); % labelling the plot
ylabel('Current I');
title('V-I Curve');
legend('Given data','Interpolated data');
hold off;
% Computing the current from given values of voltages and storing 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]; % loading V as per sheet
II=pchip(V,I,VV); % current calculation using pchip interpolation
B=[VV;II];
name='Current Calulation'; % title of text file
v='Voltage(Volt)'; % labeling the coloumns of text file
i='Current(mAmp)';
fid = fopen('Week4project.txt','w'); % creating text file
fprintf(fid,'%s\n\n',name);
fprintf(fid,'%s %s\n',v,i);
fprintf(fid,'%f %f\n',B);
fclose(fid);
figure(2)
plot(VV,II,'b'); grid;
xlabel(' Voltage(Volt)'); % labelling the plot
ylabel('Current(mAmp)');
title('Given Voltage vs Calculated current');

