Challenge

Project - Data Handling and Interpolation

% Voltage and current data
voltage = [-17.3, -17.1, -17, -16.8, -16.5, -16, -15, -14, -12, -10, -8, -5, -2, -0.2, 0.09, 0.19, 0.27, 0.39, 0.43, 0.5, 0.55, 0.6, 0.62, 0.65];
current = [-28, -24, -19, -14, -9, -6, -4, -3, -2, -1.3, -1, -0.6, -0.3, -0.1, 0, 0, 0, 0.01, 0.03, 0.17, 0.42, 1.23, 1.99, 3.91];
% Perform interpolation
query_points = -17.3:0.1:0.9;
interpolated_voltage = interp1(current, voltage, query_points, 'linear');
% Generate an interactive plot
figure;
plot(current, voltage, 'bo-', 'LineWidth', 1.5);
hold on;
plot(query_points, interpolated_voltage, 'r-', 'LineWidth', 1.5);
xlabel('Current (mA)');
ylabel('Voltage (V)');
title('Interpolated Voltage vs Current');
legend('Original Data', 'Interpolated Data');
grid on;
hold off;
% Allow user interaction to select points
disp('Click on the plot to select points. Press Enter when done.');
[interact_current, interact_voltage] = ginput();
% Store interpolated data in a text file
output_filename = 'interpolated_data.txt';
fid = fopen(output_filename, 'w');
fprintf(fid, 'Current\tVoltage\n');
for i = 1:numel(query_points)
fprintf(fid, '%.2f\t%.2f\n', query_points(i), interpolated_voltage(i));
end
fclose(fid);
disp('Interpolated data stored in "interpolated_data.txt".');
% Save the MATLAB code
code_filename = 'interpolation_code.m';
current_code = fileread(code_filename);
new_code_filename = 'interpolation_code_with_data.m';
fid = fopen(new_code_filename, 'w');
fprintf(fid, '%s\n', current_code);
fclose(fid);
disp('MATLAB code saved as "interpolation_code_with_data.m".');
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.