Challenge

Project - Data Handling and Interpolation

Solution:  % Project: Data Handling and Interpolation
 
V_I=xlsread('VI.xlsx');               % Reading xls file in matrix V_I
V=V_I(:,1);                              % Storing 1st column in 'V' array
I=V_I(:,2);                               % Storing 2nd column in 'I' array
Vq=-17.3:0.1:0.9;                     % Defining new range for interpolation in Vq
Iq=interp1(V,I,Vq,'spline');         % Interpolating using spline method and storing in Iq
plot(V,I,'r*',Vq,Iq,'--b');                % Plotting V-I alongwith interpolated Vq-Iq
hold; grid;
title('V-I Graph'); xlabel('Voltage(in V)'); ylabel('Current(in mA)');    %labelling of plot
legend('V-I','Vq-Iq');
A=[Vq;Iq];                               % Storing Vq and Iq vector in 1st and 2nd row of A matrix
fileId=fopen('VqIq.txt','w');           % Opening a new text file to store the Interpolated V-I data
fprintf(fileId,'%5s %10s\n','Vq','Iq');         % Adding Header to text file with string type
fprintf(fileId,'%2.2f %5.2f\n',A);          % Writing data from A matrix in text file with float type
fclose(fileId);                                      % Closing the file
 
Note: mfile, text file and plot is attached herewith.
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.