Challenge

Project - Data Handling and Interpolation

M-script:

% Project 
% In a laboratory experiment, data of voltage and current has been recorded and the same is attached in an excel file 
% Read the excel file in the Matlab program and 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.

clc
clear all
close all

voltage=xlsread('VI.xlsx','sheet1','A2:A25'); %reads and store first column of excel sheet1 to variable voltage
current=xlsread('VI.xlsx','sheet1','B2:B25'); %reads and store second column of excel sheet1 to variable current

x=[-17.3:0.1:0.9]; %voltage as given in question with sampling 0.1
y=interp1(voltage,current,x,'spline'); %interpolates curresponding current value for each voltage values using sline method

V_known=xlsread('VI.xlsx','sheet2','A1:A11'); %known voltage values given in sheet2
I_unknown=interp1(voltage,current,V_known,'spline'); %interpolate corresponding current values for voltages in sheet2

edit('V_vs_I_data.txt'); %creates or edits text file
fid=fopen('V_vs_I_data.txt','w'); %declaring write permission to the file
fprintf(fid,'Interpolated data of voltage and current:\n'); %title of the text file
for i=1:length(x)      
    fprintf(fid, '\n For Voltage V=%fv, Current I=%fmA',x(i),y(i)); %writes the voltage & curresponding current value to the file one by one
end
fprintf(fid,'\n\n\n\nInterpolated unknown current values for given known voltage values:\n'); %second heading in the text file
for i=1:length(V_known)      
    fprintf(fid, '\n For Voltage V=%fv, Current I=%fmA',V_known(i),I_unknown(i)); %writes the voltage & curresponding current value to the file one by one
end
fclose(fid);

plot(voltage,current,'bo',x,y,V_known,I_unknown,'ro');%plots both known data and interpolated data
grid on;
title('Data interpolation for a lab experiment');
xlabel('Voltage in v');
ylabel('Current in mA');
set(gca,'XMinorTick','on','YMinorTick','on'); %set x and y ticks
legend('Known data points','Interpolated data','unknown data points');

Execution and Result:

Downloaded the given excel file and placed in the matlab current project path and then executed the mscript.

Since we have not created the text file already it prompted for creation

Selected yes

Then it created the text file and populated all datas

Note: complete text file is attached below

Plot:

Hence using the interp1 function we were able to find the unknown current values for the given voltage values in the question.

Interpolated unknown current values for given known voltage values:

For Voltage V=-17.200000v, Current I=-28.173426mA
For Voltage V=-13.000000v, Current I=-2.429766mA
For Voltage V=-11.000000v, Current I=-1.610323mA
For Voltage V=-9.000000v, Current I=-1.116443mA
For Voltage V=-6.000000v, Current I=-0.744512mA
For Voltage V=-1.000000v, Current I=-0.290596mA
For Voltage V=0.110000v, Current I=0.001150mA
For Voltage V=0.250000v, Current I=-0.000137mA
For Voltage V=0.500000v, Current I=0.170000mA
For Voltage V=0.610000v, Current I=1.566533mA
For Voltage V=0.660000v, Current I=4.809200mA

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.