Challenge

Project - Data Handling and Interpolation

OBJECTIVE:

In a laboratory experiment, data of voltage and current has been recorded and the same is attached in an excel file ( Click on this link VI.xlsx ). 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.

MATLAB CODE:

MATLAB CODE EXPLAINATION:

  1. The clear command clears all variables from the workspace.
  2. The close all command closes all figures.
  3. The clc command clears the command window.
  4. The xlsread function reads an Excel file named "VI.xlsx" and returns the data as a matrix, which is stored in the data variable.
  5. The voltage and current data are extracted from the data matrix using indexing and stored in the voltage and current variables, respectively.
  6. The range of voltages for interpolation and extrapolation is defined using the : operator and stored in the interp_voltages and extrap_voltages variables, respectively.
  7. The interp1 function performs linear interpolation of the current data. It takes the voltage and current data, the range of voltages for interpolation, and the options 'linear' and 'extrap' to specify linear interpolation and extrapolation beyond the range of the input data, respectively. The interpolated current data is stored in the interp_current variable.
  8. The interp1 function is used again to extrapolate the current for the specified voltages, which are beyond the range of the input data. The extrapolated current data is stored in the extrap_current variable.
  9. The fopen function opens a file named "interpolated_data.txt" in write text mode and returns a file identifier, which is stored in the fid variable.
  10. The fprintf function writes the headers and data into the file using tab and newline characters to separate the values. The interpolated data is written first, followed by the extrapolated data with a header that indicates it is the extrapolated data.
  11. The fclose function closes the file.
  12. The winopen function opens the file "interpolated_data.txt" using the default text editor of the operating system.
  13. The plot function creates a figure with three curves: the original data as blue circles, the interpolated data as a red line, and the extrapolated data as a green line. The hold on and hold off commands are used to keep the previous plot and add new plots to the same figure. The xlabel, ylabel, title, and legend functions add labels, title, and a legend to the plot. The 'LineWidth' option specifies the width of the lines used for the curves.

RESULT:

  1. The plot shows the vi characteristics from the input and output data.
  2. Blue dots is the original data from the vi.xlsx file
  3. Red+green line is the interpolated data.
  4. Green line is the extrapolated data.(positions are marked)

CONCLUTION:

  • The above script file(matlabbasicproject.m) has been attached.
  • The results in txt file(interpolated_data.txt) has been attached.

Pros:

  • The code is well-organized and commented, making it easy to understand and modify.
  • The code uses built-in MATLAB functions, which are efficient and optimized for performance.
  • The code provides a visualization of the data and the results, which can help in understanding the behavior of the system being analyzed.

Cons:

  • The code assumes that the input data is valid and error-free, without any missing or corrupted values.
  • The code uses linear interpolation and extrapolation, which may not be suitable for all types of data and systems. More advanced interpolation and extrapolation methods could be used to improve the accuracy of the results.
  • The code saves the results in a text file, which may not be the most efficient or flexible way to store and share the data.
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.