Project - Data Handling and Interpolation
We download the file VI.xlsx from the question.
We substitute the values of VI.xlsx to z and store first column and then second column values of VI file to volt and current variables.
>> z = xlsread('VI.xlsx');
>> volt = z(:,1);
>> current = z(:,2);
We create a given range of -17.3:0.1:0.9 to perform the interpolation and plot the graph for given range and provide labels, grids as well as title.
We save the plotted graph as pdf file.
>> X = -17.3:0.1:0.9;
>> Y = interp1(volt,current,X);
>> figure(1);
>> plot(volt,current,'X');
>> grid;ylabel('Amp');xlabel('voltage');title('VI file data');
>> print('VI file data','-dpdf');
Then, we need to plot the next graph having values of X(range) and interpolated values Y.
and plot the graph for given range and provide labels, grids as well as title.
We save the plotted graph as pdf file.
>> figure(2);
>> plot(X,Y);
>> grid;ylabel('Y');xlabel('X');title('Linear Intp.');
>> print('Linear Interpolation','-dpdf');
>> figure(3);
>> plot(volt,current,'*',X,Y);
>> grid;ylabel('Ampere');xlabel('Voltage');title('Cross checking with the validated points');
>> legend('VI file data','values when interpolated');
>> print('Cross checked graph','-dpdf');
Now according to the question we take the set of values for given voltages VV and use interpolation function.
We then plot the graph in figure 4 and provide labels, grids as well as title.
We save the plotted graph as pdf 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];
>> X1=interp1(volt,current,VV,'spline');
>> figure(4);
>> plot(VV,X1,'O');
>> grid;ylabel('Ampere');xlabel('Voltage');title('VV','values');
>> print('VV values','-dpdf');
We write the interpolated values into the text file by creating a new text file called X1 in the Matlab folder.
We create a heading for the text file using 'fprintf' function.
We use %f to read the floating points and %fn to store the values in the next line to the length of file in X1.
>> fid=fopen('X1.txt','w');
>> fprintf(fid,'Voltage Currentn');
>> len=length(X1);
>> for i=1:len,
fprintf(fid,'%f %fn',VV(i),X1(i));
end;