linear interpolation for the curves
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
I have 2 curves of pressure. Pressure represents y-axis and x-axis is the time. There is some difference between the 2 curves. First i have to interpolate to find the pressure for the missing time and secondly I have to find the relative error between the two existing curves using RMS.
Please help me in writing the codes for finding the pressure for the missing time considered as a target time using linear interpolation and for finding the relative error using RMS.
I have attached the excel sheet for better understanding
0 Commenti
Risposte (2)
Star Strider
il 31 Lug 2023
There are missing data, however they are all at the end of the first -time-pressure values. Filling them would require extrapolation, and that is to be strictly avoided here because that would require creating data where not previously existed, rather than interpolating intermediate missing values.
One approach —
% C1 = readcell('DENSITY_BASED_SOLVER.xlsx')
T1 = readtable('DENSITY_BASED_SOLVER.xlsx', 'VariableNamingRule','preserve', 'HeaderLines',1)
VN = T1.Properties.VariableNames;
t{1} = T1{:,1};
p{1} = T1{:,2};
t{2} = T1{:,6};
p{2} = T1{:,8};
% Q1 = nnz(isnan([p{1}]))
% Q11 = nnz(isnan(t{1}))
% Q12 = find(isnan(p{1}))
% t{1}(Q12-1)
% find(diff(Q12)>1)
% Q2 = nnz(isnan([t{2},p{2}]))
figure
plot(t{1}, p{1}, 'DisplayName','First Set')
hold on
xline(t{1}(484), '--r', 'DisplayName','Finite Time Limit')
plot(t{2}, p{2}, 'DisplayName','Second Set')
hold off
grid
xlabel('Time (ms)')
ylabel('Pressure (MPa)')
title('Original')
legend('Location','best')
[min_time_ends,idx] = min([t{1}(end) t{2}(end)]) % Shortest Time Vector & Set Number ('idx')
tq{1} = t{1}(~isnan(t{1})); % Eliminiate the 'NaN' Values So The Interpolation Will Work
[tq{1},idx] = unique(tq{1}); % Eliminate Duplicate Time Values, Return Unique Time Values & Associated Index
pq{1} = p{1}(idx); % Pressure Values At Unique Time Values
pq{1} = interp1(tq{1}, pq{1}, t{2}); % Interpolate Longer Pressure (p{2}) To Shorter Time Vector (t{1})
pdif = p{2} - pq{1}; % Pressure Difference
figure
plot(t{2}, pq{1}, 'DisplayName','First Set (Interpolated)')
hold on
plot(t{2}, p{2}, 'DisplayName','Second Set')
plot(t{2}, pdif, ':k', 'DisplayName','Pressure Difference')
hold off
grid
xlabel('Time (ms)')
ylabel('Pressure (MPa)')
title('Processed')
legend('Location','best')
Processing these data are not straightforward.
.
0 Commenti
Chhayank Srivastava
il 31 Lug 2023
Modificato: Chhayank Srivastava
il 31 Lug 2023
I included the data with some cleaning to be imported by MATLAB and named the sheet "Data".
Few assumptions were made, as I didnt which pressure input you wanted to consider MPa or Pascals but nonetheless the code's logic will be similar.
clear; clc;
data = readtable('DENSITY_BASED_SOLVER.xlsx',"Sheet","Data");
%Pressure data 1 (pascals)
p_1(:,1) = data{:,1};
p_1(:,2) = data{:,2};
%Pressure data 2 (pascals)
p_2(:,1) = data{:,9};
p_2(:,2) = data{:,10};
%missing time ... Random points in time for 1D interpolation
time = rand(1,15);
%Interpolation .. I included all the data points but you can reduce data points closer to the relevant area for interpolation
% This can be done by changing interp1(p_1(:,1),p_1(:,2),time) to interp1(p_1(st_intv:end_intv,1),p_1(st_intv:end_intv,2),time)
val_1 = interp1(p_1(:,1),p_1(:,2),time);
val_2 = interp1(p_2(:,1),p_2(:,2),time);
%RMSE
error = rmse(val_1,val_2)
0 Commenti
Vedere anche
Categorie
Scopri di più su Curve Fitting Toolbox in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!