Project - Data Handling and Interpolation
Q.
Answer:-
INPUT
A = xlsread('VI.xlsx'); %Reading the excel file
V = A(:,1); %storing first column value of 'A' in 'V'
I = A(:,2); %storing second column value of 'A' in 'I'
V_Range = -17.3:0.1:0.9; % Creating Given Range of Voltage Data mentioned in problem
I_Range = interp1(V,I,V_Range,"spline"); % Using 'interp1' function to calculate Current value for given Voltage Range 'V_Range'
figure(1);
subplot(221)
plot(V,I,'-m'); % Ploting the values
grid;
title('Experimented Data'); %giving title for the subplot
xlabel('V(Volt)'); %giving lables to both the axis
ylabel('I(mAmp)');
axis([-20 5 -30 5]);%Defining axis limits
subplot(222)
plot(V_Range,I_Range,'-o'); % Ploting the values
grid;
title('Calculated Data'); %giving title for the subplot
xlabel('V(Volt)'); %giving lables to both the axis
ylabel('I(mAmp)');
axis([-20 5 -30 5]); %Defining axis limits
subplot(223)
plot(V,I,'-r',V_Range,I_Range,'-b'); %Ploting the values
grid;
title('Voltage(V) vs Current(I) Validation plot');%giving title for the subplot
xlabel('V(Volt)'); %labeling X and Y axis
ylabel('I(mAmp)');
axis([-20 5 -30 5]); %Defining axis limits
legend('Experimented Data','Calculated Data','Location','northwest');% Showing legends
VV=[-17.3 -17.1 -17 -16.8 -16.5 -16 -15 -14 -12 -10 -8 -5 -2 -0.20 0.09 0.19 0.27 0.39 0.43 0.50 0.55 0.60 0.62 0.65]; % Given Voltage Data in problem
VI = interp1(V,I,VV,"spline");% Using 'interp1' function for calculating Current value for given Voltage
subplot(224)
plot(VV,VI,'-r'); %Ploting the values
grid;
title('Calculated Value Of I(mAmp) Vs Given data of V(Volt)'); %giving title for the subplot
xlabel('V(Volt)');
ylabel('I(mAmp)'); %labeling X and Y axis
axis([-20 5 -30 5]); %Defining axis limits
fid = fopen('Project matlab basics data.txt','w');% opening output file
fprintf(fid,'V(Volt) I(mAmp)\n');% storing value of variable x in file
for i = 1:length(VV)
fprintf(fid,'%.3f %.3f\n',VV(i),VI(i));% storing value of variable x in file
end
fclose(fid);% closing output file

OUTPUT

