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
댓글 수: 0
채택된 답변
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(:))
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
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'})
The calculations using ‘Frequencei’ (‘Frequence’ interpolated) wouild go similarly.
.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Electrophysiology에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!