filling missing values in column with obtained results

조회 수: 2(최근 30일)
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

채택된 답변

Star Strider
Star Strider 2021년 6월 27일
편집: Star Strider 2021년 6월 27일
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(:))
Filled = 11×2
1.0e+04 * 0.2993 0.0006 0.4014 0.0015 0.5036 0.0024 0.6150 0.0032 0.6919 0.0041 0.7891 0.0050 0.8862 0.0059 1.0175 0.0067 1.1488 0.0076 1.2516 0.0085
FilledTable = table(OrderInterp(:),Filled(:,1),Filled(:,2), 'VariableNames',{'Order','TBFi','Frequence'})
FilledTable = 11×3 table
Order TBFi Frequence _____ ______ _________ 1 2993 6 2 4014.5 15 3 5036 24 4 6150 32 5 6919 41 6 7890.5 50 7 8862 59 8 10175 67.5 9 11488 76 10 12516 85 11 13545 94
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')
ans =
' Order TBFi Frequence '
sprintf('\t%2.0f\t%6.0f\t\t%3.0f\n', [OrderInterp(:) Filled]')
ans =
' 1 2993 6 2 4014 15 3 5036 24 4 6150 32 5 6919 41 6 7890 50 7 8862 59 8 10175 68 9 11488 76 10 12516 85 11 13545 94 '
EDIT — (27 Jun 2021 at 20:02)
Added sprintf calls after noticing R2012a.
.
  댓글 수: 7
Star Strider
Star Strider 2021년 6월 28일
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'})
RFfy = 11×5 table
Order R F f y _____ _______ ________ __________ __________ 1 0.92253 0.077475 5.4682e-05 5.9275e-05 2 0.8574 0.1426 7.2291e-05 8.4314e-05 3 0.7762 0.2238 8.5905e-05 0.00011067 4 0.67488 0.32512 9.4933e-05 0.00014067 5 0.60075 0.39925 9.7339e-05 0.00016203 6 0.50643 0.49357 9.6069e-05 0.0001897 7 0.41545 0.58455 9.0594e-05 0.00021806 8 0.3041 0.6959 7.827e-05 0.00025738 9 0.21125 0.78875 6.2896e-05 0.00029774 10 0.15297 0.84703 5.0481e-05 0.00033001 11 0.10713 0.89287 3.8867e-05 0.00036281
The calculations using ‘Frequencei’ (‘Frequence’ interpolated) wouild go similarly.
.

댓글을 달려면 로그인하십시오.

추가 답변(0개)

제품


릴리스

R2012a

Community Treasure Hunt

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

Start Hunting!

Translated by