filling missing values in column with obtained results
2 views (last 30 days)
Show older comments
firrou bouteflika
on 27 Jun 2021
Commented: Star Strider
on 28 Jun 2021
clear all; clc; format long;
TBFi = [2993 5036 6150 6919 8862 11488 13545];
Frequence = [6 24 32 41 59 76 94];
p = polyfit(TBFi,Frequence,1);
x_min = min(TBFi);
x_max = max(TBFi);
d_min = polyval(p,x_min);
d_max = polyval(p,x_max);
N=11;
i=[2;6;8;10];
missing_frequences=(i-0.3)/(N+.4)
missing_TBFi=((missing_frequences.*10^2)-p(2))/p(1)
both t and freq are my replaced manually by me
0 Comments
Accepted Answer
Star Strider
on 27 Jun 2021
Edited: Star Strider
on 27 Jun 2021
Try this —
Order = [1 3 4 5 7 9 11].';
TBFi = [2993 5036 6150 6919 8862 11488 13545].';
Frequence = [6 24 32 41 59 76 94].';
OrderInterp = 1:11;
Filled = interp1(Order, [TBFi Frequence], OrderInterp(:))
FilledTable = table(OrderInterp(:),Filled(:,1),Filled(:,2), 'VariableNames',{'Order','TBFi','Frequence'})
It uses the interp1 function (introduced before R2006a) and the default linear interpolation to fill the table.
The table call is useful, however lacking it:
sprintf('\n\tOrder\tTBFi\t Frequence\n')
sprintf('\t%2.0f\t%6.0f\t\t%3.0f\n', [OrderInterp(:) Filled]')
EDIT — (27 Jun 2021 at 20:02)
Added sprintf calls after noticing R2012a.
.
7 Comments
Star Strider
on 28 Jun 2021
Doing a linear interpolation would appear to be appropriate:
Order = [1 3 4 5 7 9 11].';
TBFi = [2993 5036 6150 6919 8862 11488 13545].';
Frequence = [6 24 32 41 59 76 94].';
OrderInterp = 1:11;
Filled = interp1(Order, [TBFi Frequence], OrderInterp(:));
TBFii = Filled(:,1); % Interpolated 'TBFi'
Frequncei = Filled(:,2); % Interpolated 'Frequence'
% FilledTable = table(OrderInterp(:),Filled(:,1),Filled(:,2), 'VariableNames',{'Order','TBFi','Frequence'})
figure
yyaxis left
hyl = plot(Order, TBFi, 'p');
hold on
plot(OrderInterp, Filled(:,1),'+-', 'Color',hyl.Color)
hold off
ylabel('TPi')
yyaxis right
hyr = plot(Order, Frequence, 'p');
hold on
plot(OrderInterp, Filled(:,2), '+-', 'Color',hyr.Color)
hold off
ylabel('Frequence')
grid
I seriously doubt that a linear regression would produce comparable or more accurate results. However if you want to use that approach, the code in my previous Comment is more efficient than using polyfit and polyval, each twice, in order to achieve the same result.
Then:
R = @(TBFi) exp(-((TBFi/9400).^2.2));
F = @(TBFi) 1-exp(-((TBFi/9400).^2.2));
f = @(TBFi) (2.2/9400).*((TBFi/9400).^1.2).*exp(-((TBFi/9400).^2.2));
y = @(TBFi) (2.2/9400).*((TBFi/9400).^1.2);
would produce (again using a table for convenience):
RFfy = table(OrderInterp(:),R(TBFii),F(TBFii),f(TBFii),y(TBFii), 'VariableNames',{'Order','R','F','f','y'})
The calculations using ‘Frequencei’ (‘Frequence’ interpolated) wouild go similarly.
.
More Answers (0)
See Also
Categories
Find more on Electrophysiology in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!