Linear FillMissing producing incorrect values?
Show older comments
My Code involves filling in missing values using linear interpolation, but its plain to see that the values its giving are wrong. User error or matlab bug? Instead of interpolating the missing value for 76.82, its simply halving the previous value and calling it a day. Thanks in advance guys!
Baye2 =
0 0
14.1800 NaN
29.0625 7.7096
58.1250 0
74.5625 4.3605
76.8200 NaN
91.0000 0
Bayee2 =
0 0
14.1800 3.8548
29.0625 7.7096
58.1250 0
74.5625 4.3605
76.8200 2.1803
91.0000 0
%Inputs%
%example from bottom horizontal on D11.10z%
clear
clc
DP = 38.2; %Design pressure in psf
ML = 91; %Mullion length in inches
B1W = 28.36; %Bay 1 width in inches
B2W = 60.67; %Bay 2 width in inches
B1BP = []; %Bay 1 break points in inches seperated by spaces
B2BP = [58.125]; %Bay 2 break points in inches seperated by spaces
B1 = [0 0];
B2 = [0 0];
if isempty(B1BP) %if there is only a single loading on bay 1 (no breakpoints)
if ML > B1W % Trapezoidal loading
B1 = [0 0; B1W/2 B1W/2/144*DP; ML-B1W/2 B1W/2/144*DP; ML 0];
else %Triangular loading
B1 = [0 0; ML/2 ML/2/144*DP; ML 0];
end
else %if there are multiple loadings for bay 1
B1BP = [0 B1BP ML];
for n = 1:length(B1BP)-1 %for each loading on bay 1
if (B1BP(n+1)-B1BP(n)) > B1W % Trapezoidal loading
Bn1s{n} = [B1BP(n) 0; B1BP(n)+B1W/2 B1W/2/144*DP; B1BP(n+1)-B1W/2 B1W/2/144*DP; B1BP(n+1) 0];
Bn1 = [B1BP(n) 0; B1BP(n)+B1W/2 B1W/2/144*DP; B1BP(n+1)-B1W/2 B1W/2/144*DP; B1BP(n+1) 0];
B1 = [B1; Bn1];
n=n+1;
else %Triangular loading
Bn1s{n} = [B1BP(n) 0; B1BP(n)+(B1BP(n+1)-B1BP(n))/2 (B1BP(n+1)-B1BP(n))/2/144*DP; B1BP(n+1) 0];
Bn1 = [B1BP(n) 0; B1BP(n)+(B1BP(n+1)-B1BP(n))/2 (B1BP(n+1)-B1BP(n))/2/144*DP; B1BP(n+1) 0];
B1 = [B1; Bn1];
n=n+1;
end
end
end
B1 = unique(B1,'rows');
if isempty(B2BP) %if there is only a single loading on bay 2 (no breakpoints)
if ML > B2W % Trapezoidal loading
B2 = [0 0; B2W/2 B2W/2/144*DP; ML-B2W/2 B2W/2/144*DP; ML 0];
else %Triangular loading
B2 = [0 0; ML/2 ML/2/144*DP; ML 0];
end
else %if there are multiple loadings for bay 2
B2BP = [0 B2BP ML];
for j = 1:length(B2BP)-1 %for each loading on bay 1
if (B2BP(j+1)-B2BP(j)) > B2W % Trapezoidal loading
Bn2s{j} = [B2BP(j) 0; B2BP(j)+B2W/2 B2W/2/144*DP; B2BP(j+1)-B2W/2 B2W/2/144*DP; B2BP(j+1) 0];
Bn2 = [B2BP(j) 0; B2BP(j)+B2W/2 B2W/2/144*DP; B2BP(j+1)-B2W/2 B2W/2/144*DP; B2BP(j+1) 0];
B2 = [B2; Bn2];
j=j+1;
else %Triangular loading
Bn2s{j} = [B2BP(j) 0; B2BP(j)+(B2BP(j+1)-B2BP(j))/2 (B2BP(j+1)-B2BP(j))/2/144*DP; B2BP(j+1) 0];
Bn2 = [B2BP(j) 0; B2BP(j)+(B2BP(j+1)-B2BP(j))/2 (B2BP(j+1)-B2BP(j))/2/144*DP; B2BP(j+1) 0];
B2 = [B2; Bn2];
j=j+1;
end
end
end
B2 = unique(B2,'rows');
B1L = B1(:,1); %extracts just the locations from the Bay 1 loadings
B1z = NaN(size(B1L,1),1); %creates a column of unknowns the length of the locations
B1L = [B1L B1z]; %combines these two columns
B2L = B2(:,1);
B2z = NaN(size(B2L,1),1);
B2L = [B2L B2z];
B1 = [B1;B2L];
B1 = sortrows(B1);
[Bay1, ia] = unique(B1(:,1),'rows');
Baye1 = B1(ia,:);
Bayee1 = fillmissing(Baye1,'linear');
B2 = [B2;B1L];
B2 = sortrows(B2);
[Bay2, ib] = unique(B2(:,1),'rows');
Baye2 = B2(ib,:)
Bayee2 = fillmissing(Baye2,'linear')
Loadings = [Bayee1(:,1) Bayee1(:, 2) + Bayee2(:, 2)];
Loadings = round(Loadings, 2);
Accepted Answer
More Answers (0)
Categories
Find more on Logical 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!