How do i inpolate two difference vectors to same length

Hello Community
I have two different datasets in .xlsx and .csv format. Both are made by logging physical sensors. The reference for all data is rpm (rounds per minute) which is representated in both documents. Besides this there is also a "Fuel usage" in the first document and "power measurement" in the other document.
My problem is i need to calculate the fuel efficiency -> the fuel usage rate compared to power level of engine. But the two vectors are of size 1:770 and 1:4620. That makes it impossible to compare data.
Is there any way to interpolate both vectors, so vector start at 800rpm and stop at 2500rpm with 10rpm step, and connect this rpm referance to fuel usage and power level?
I will really appreciate a solution on this.

 採用された回答

Ameer Hamza
Ameer Hamza 2020 年 3 月 16 日

1 投票

Attach a sample dataset for a more specific example.

3 件のコメント

Ameer Hamza
Ameer Hamza 2020 年 3 月 16 日
This code shows an example of how to use interp1 to match the length of two vectors
%% Reading the data
data1 = readtable('Enginepower.csv', 'HeaderLines', 7);
% the file use comma as decimal seperator, extra steps are requred to get
% numeric data
variables_names = data1.Properties.VariableNames;
for i=1:numel(variables_names)
if isa(data1.(variables_names{i}), 'cell')
data1.(variables_names{i}) = str2double(strrep(data1{:,i}, ',', '.'));
end
end
%% process the data
data1_rpm = data1.RPM;
data1_power = data1.EnginePower_HP_;
data2 = readtable('Fuelusage.xlsx');
[data2_rpm, index] = unique(data2.Rpm); % there are some repeated values of rpm which cause issues with interp1
data2_fuel = data2.Fuelusage_L_h_(index);
rpm_vector = 800:10:2200;
power_interp = interp1(data1_rpm, data1_power, rpm_vector, 'linear', 'extrap');
fuel_interp = interp1(data2_rpm, data2_fuel, rpm_vector, 'linear', 'extrap');
However, note that for some value of rpm, the data of power and fuel consumption is not available, interp1 need to extrapolate. That can output unusual values in some cases, but that is the property of data and extrapolation method, the overall method is the same.
Mads Petersen
Mads Petersen 2020 年 3 月 19 日
Thank you very much for your help and solution! Its highly apriciated
Cheers
Ameer Hamza
Ameer Hamza 2020 年 3 月 19 日
Glad to be of help.

サインインしてコメントする。

その他の回答 (1 件)

Mads Petersen
Mads Petersen 2020 年 3 月 16 日

0 投票

Thank you for answer. I have already tried the interp1 function without succes.
I have attached both enginepower document and fuelusage document.
If you, or anyone else have the time to create a code for makin this work i can pay for solution, as i am in a bit of hurry. thanks

1 件のコメント

Mads Petersen
Mads Petersen 2020 年 3 月 16 日
Code must work on all kind of vector lengths, as they depend on measuring time. but the rpm is always in interval [800;2500]

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeInterpolation についてさらに検索

製品

リリース

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by