Challenge

Project - Data Handling and Interpolation

Answer:

Aim:

  • To read the excel file given
  • To perform the interpolation in the range of -17.3:0.1:0.9.
  • Generate the interactive plot for the interpolated data and store them in a text file

Code:

clear;

clc;

% interpolation of voltage and current data
D=xlsread('VI');% reading excel file data
x=D(:,1); % voltage data seperating
y=D(:,2); % current data seperating
xq=[-17.3:0.1:0.9]; % Given interpolation range
yq1=interp1(x,y,xq); % linear interpolation
yq2=interp1(x,y,xq,'spline'); % spline interpolation
figure(1)% Linear interpolation plotting
plot(x,y,'o',xq,yq1,':');grid on;
title('Linear Interpolation');
xlabel('Voltage (V)');ylabel('Current (I)');
legend('Actual Value', 'Interpolated value', 'location','northwest');
figure(2)% spline interpolation plotting
plot(x,y,'o',xq,yq2,':');grid on;
title('Spline Interpolation');
xlabel('Voltage (V)');ylabel('Current (I)');
legend('Actual Value', 'Interpolated value', 'location','Northwest');
% saving the interpolation data into text file
%opening text file
v_i_out=fopen('VI_output.txt','w');
fprintf(v_i_out,' Voltage Current\n');
%writing voltage & current value
fprintf(v_i_out,'%4.3f %5.3f\n',xq,yq2);
%'savefig'command is used to save the figures
savefig(1,'linear.fig');savefig(2,'spline.fig');
fclose(v_i_out);
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.