Project - Data Handling and Interpolation
Reading the given data to the matlab
>> fid=xlsread('VI.xlsx');%read the xlsx file from given data.fed is the file pointer
>> V=fid(:,1);%save the voltage values (first column)
>> I=fid(:,2);%save the current values (second column)
>> V1=[-17.3:0.1:0.9];%given data that is to be interpolated
>> I1=interp1(V,I,V1);%interpolated values for corresponding values of V1
>> I2=interp1(V,I,V1,'spline');%interpolated values for corresponding values of V1 in spline formation
>> subplot(221);%ploting the first graph of 2 by 2 matrix
>> plot(V,I,'b-');title('VI-graph');xlabel('v');ylabel('i');%ploting the V-I graph from given data
>> grid;%giving the grid to the graph
>> subplot(222);%ploting the second graph of 2 by 2 matrix
>> plot(V1,I1,'m-');title('V1-I1');xlabel('v');ylabel('i');%ploting the graph interpolated values
>> grid;%giving the grid to the graph
>> subplot(223);%ploting the third graph of 2 by 2 matrix
>> plot(V,I,'o',V1,I1,':');title('VI-graph(interpolated)');xlabel('v');ylabel('i');%ploting the interpolated values with original in spline form
>> grid;%giving the grid to the graph
>> subplot(224);%ploting the fourth graph of 2 by 2 matrix
>> plot(V,I,'o',V1,I2,':');title('VI-graph(spline)');xlabel('v');ylabel('i');%ploting the interpolated values with original in spline form
>> grid;%giving the grid to the graph
>> print('VI-graph','-dpdf');%saving the graph in pdf form
ploting the interpolated data in the graph
>> figure(2);
>> plot(V,I,'o',V1,I1,':');title('VI-graph(interpolated)');xlabel('v');ylabel('i');
>> legend('original data','interpolated data');
>> print('VI-graph(interpolated)','-dpdf');
ploting the original data
figure(3);
plot(V,I,'b-');title('VI-graph');xlabel('v');ylabel('i');
print('VI-graph(original)','-dpdf');
ploting the interpolated values for given values of voltage
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];%given voltage values in the question
II=interp1(V,I,VV,'spline');%finding the corresponding values of VV
figure(4);
plot(V,I,'o',VV,II,'*');xlabel('voltage');ylabel('current');title('validated value');%including the values of VV and II in V-I graph by using interpolation method
>> legend('original values','validated value');
Writing the values of VV and II into the text file
>>fll=fopen('voltage-current1.txt','w');%creating the text file
>> l=length(II);%finding the length of the II vector
>> fprintf(fll,'voltage current\n');%writing the headings in the text file
>> for i=1:l
fprintf(fll,'%f %f\n',VV(i),II(i));%writing the values of VV and II
end;
>> fclose(fll);%closing the file pointer