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 个评论
firrou bouteflika
firrou bouteflika 2021-6-28
this is how i imagined it in my head
i give him this
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)
and now i tell him where to fill the empty spots with results (missing_TBFi and missing_frequences)
TBFi = [2993 [1] 5036 6150 6919 [2] 8862 [3] 11488 [4] 13545];
Frequence = [6 [1] 24 32 41 [2] 59 [3] 76 [4] 94];
so that i get a new full 'TBFi' (wich i called 't' because i had to seperate their name because i insert them manually but if i can get them automatically i will call them TBFi or not)
TBFi = [2993;3938.1;5063;6150;6919;8165.8;8862;10279;11488;12392.3;13545];
to use after in some equations (i wont use frequence in this part i just want to see them together)
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);
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 个)

类别

Help CenterFile Exchange 中查找有关 Electrophysiology 的更多信息

产品


版本

R2012a

Community Treasure Hunt

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

Start Hunting!

Translated by