Challenge

Project - Data Handling and Interpolation

#PROGRAM CODE

%% performing the interpolationVI = xlsread('VI.xlsx');
V = VI(:,1);
I = VI(:,2);
VI = [-17.3:0.1:0.9]; % The range in which interpolation carried out
V1 = interp1(V,I,VI); % Performing linear interpolation
V2 = interp1(V,I,VI,'spline'); % Performing Spline interpolation

figure(1)
plot(V,I,'o',VI,V1,':.','Linewidth',2); grid; % plot for linear interpolation
xlabel("Voltage(V)"); % labelling voltage in x-axis
ylabel("Current(I)"); % labelling current in the Y-axis
title("Linear interpolation"); % To give the title on the plot
legend('Actual value','interpolated value','Location','Southeast');

figure(2)
plot(V,I,'b',VI,V2,':.','Linewidth',2); grid; % Performing Spline interpolation plot
xlabel("Voltage(V)");
ylabel("Current(I)");
title("Spline interpolation");
legend('Actual value','interpolated value','Location','Northwest');

%% Final interpolation
VV1 = [-17.5 -13.4 -12.6 -11.3 10.2 0.25 0.5 0.61 0.66]; % taking new voltage values
VV2 = interp1(V,I,VV1,'spline'); % Performing Spline interpolation

figure(3)
plot(VV1,VV2,'o--','Linewidth',2); grid; % Plotting Linear Interpolation
xlabel('New Voltage values (V)');
ylabel('New Current values (I)');
title("Final interpolation");

%% Saving Output Files
VI_output = [VV1;VV2];
fileID = fopen('VI_linear.txt','w'); % Writing to text file
fprintf(fileID,'%6s %12s\n','Voltage','Current'); % Writing title of the columns
fprintf(fileID,'%6.2f %12.2f\n',V1); % Writing Output values

fclose(fileID);fileID = fopen('VI_spline.txt','w'); % Writing to text file
fprintf(fileID,'%6s %12s\n','Voltage','Current'); % Writing title of the columns
fprintf(fileID,'%6.2f %12.2f\n',V2); % Writing Output values
fclose(fileID);

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.