logo
down
shadow

How to interpolate and extrapolate non-monotonic vector data set in Matlab


How to interpolate and extrapolate non-monotonic vector data set in Matlab

By : user2185427
Date : November 21 2020, 04:01 AM
this will help I have a geographically distributed data set with X-coordinate, Y-coordinate and corresponding target value of interest D. That is, my data set consists from three vectors: X, Y, D. , I found out one way using scatteredInterpolant:
code :
xy = -2.5 + 5*gallery('uniformdata',[200 2],0);
x = xy(:,1);
y = xy(:,2);
v = x.*exp(-x.^2-y.^2);
F1 = scatteredInterpolant(x,y,v, 'natural');
[xq,yq] = ndgrid(-5:.1:5) % Make the grid
vq1 = F1(xq,yq); % Evaluate function values at grid of interest
surf(xq,yq,vq1)
hold on
plot3(x,y,v, 'ro', 'MarkerFaceColor', 'red')
xlabel('X')
ylabel('Y')
zlabel('V')
title('Interpolation and exrapolation based on scattered data')


Share : facebook icon twitter icon
How to interpolate vector in Matlab?

How to interpolate vector in Matlab?


By : user5945167
Date : March 29 2020, 07:55 AM
I hope this helps . You can use interp1. If t2 is a vector containing the interpolation times, then:
code :
ft2 = interp1(t, ft, t2);
interpolate and extrapolate missing columns in a data frame

interpolate and extrapolate missing columns in a data frame


By : Suraj Jayant Kulkarn
Date : March 29 2020, 07:55 AM
may help you . I have a data frame containing data for every 4 or 5 years. I wish to interpolate data for years not in the data frame and extrapolation data for columns at either end of the data frame. , Here is one alternative formulation.
First a useful function:
code :
tvseq <- function(...)t(Vectorize(seq.default)(...))
years <- as.numeric(gsub("y","",names(my.data)))

d <- diff(years)

L <- lapply(seq(d), function(i) tvseq(from=my.data[,i], to=my.data[,i+1], length.out=d[i]+1)[,-1])

result <- cbind(my.data[,1], do.call(cbind, L))
colnames(result) <- paste0("y",min(years):max(years))
> result
     y1980 y1981 y1982 y1983 y1984 y1985 y1986 y1987 y1988 y1989 y1990
[1,]   0.1  0.12  0.14  0.16  0.18   0.2  0.24  0.28  0.32  0.36   0.4
[2,]   1.0  1.20  1.40  1.60  1.80   2.0  2.40  2.80  3.20  3.60   4.0
[3,]  10.0 12.00 14.00 16.00 18.00  20.0 24.00 28.00 32.00 36.00  40.0
ylow <- 1978:(min(years)-1)
low <- tvseq(to=result[,1], by=result[,2]-result[,1], length.out=length(ylow)+1)[,1:length(ylow)]
colnames(low) <- paste0("y",ylow)

yhigh <- (max(years)+1):1992
high <- tvseq(from=result[,ncol(result)], by=result[,ncol(result)]-result[,ncol(result)-1], length.out=length(yhigh)+1)[,-1]
colnames(high) <- paste0("y",yhigh)

cbind(low, result, high)
     y1978 y1979 y1980 y1981 y1982 y1983 y1984 y1985 y1986 y1987 y1988 y1989 y1990 y1991 y1992
[1,]  0.06  0.08   0.1  0.12  0.14  0.16  0.18   0.2  0.24  0.28  0.32  0.36   0.4  0.44  0.48
[2,]  0.60  0.80   1.0  1.20  1.40  1.60  1.80   2.0  2.40  2.80  3.20  3.60   4.0  4.40  4.80
[3,]  6.00  8.00  10.0 12.00 14.00 16.00 18.00  20.0 24.00 28.00 32.00 36.00  40.0 44.00 48.00
How to interpolate random non monotonic increasing data

How to interpolate random non monotonic increasing data


By : Genie Miles
Date : March 29 2020, 07:55 AM
hope this fix your issue There is quick and dirty method if you do not know the exact function defining the foil profile. Split your data into 2 sets, top and bottom planes, so the 'x' data are monotonic increasing.
First I imported your data table in the variable A, then:
code :
%// just reorganise your input in individual vectors. (this is optional but
%// if you do not do it you'll have to adjust the code below)
x = A(:,1) ;    
y = A(:,2) ;

ipos = y >  0 ;                             %// indices of the top plane
ineg = y <= 0 ;                             %// indices of the bottom plane

xi = linspace(0,1,500) ;                    %// new Xi for interpolation

ypos = interp1( x(ipos) , y(ipos) , xi ) ;  %// re-interp the top plane
yneg = interp1( x(ineg) , y(ineg) , xi ) ;  %// re-interp the bottom plane

y_new = [fliplr(yneg) ypos] ;               %// stiches the two half data set together
x_new = [fliplr(xi) xi] ;

%% // display
figure
plot(x,y,'o')
hold on
plot(x_new,y_new,'.r')
axis equal
xi = [linspace(0,0.01,50) linspace(0.01,1,500)] ;
SQL Data to interpolate/extrapolate

SQL Data to interpolate/extrapolate


By : kekemeke godspower
Date : March 29 2020, 07:55 AM
may help you . If i have a table that keeps a running average of kW usage at a certain temperature, and I wanted to get a kW usage for a temperature that has not been recorded before, how could i get either , You can get the nearest rows using:
code :
select t.*
from temperatures t
order by abs(temperature_value - ACTUAL_TEMPERATURE) asc
limit 2 
(select t.*
 from temperatures t
 where temperature_value <= ACTUAL_TEMPERATURE
 order by temperature_value desc
 limit 1
) union
(select t.*
 from temperatures t
 where temperature_value >= ACTUAL_TEMPERATURE
 order by temperature_value asc
 limit 1
) 
select min(temperature_value) as mintv, max(temperature_value) as maxtv,
       min(temperature_current_kw) as minck, max(temperature_current_kw) as maxck
from ((select t.*
       from temperatures t
       where temperature_value <= ACTUAL_TEMPERATURE
       order by temperature_value desc
       limit 1
      ) union
      (select t.*
       from temperatures t
       where temperature_value >= ACTUAL_TEMPERATURE
       order by temperature_value asc
       limit 1
      ) 
     ) t;
select (case when maxtv = mintv then minkw
             else minkw + (ACTUAL_TEMPERATURE - mintv) * ((maxkw - minkw) / (maxtv - mintv))
        end)
from (select min(temperature_value) as mintv, max(temperature_value) as maxtv,
             min(temperature_current_kw) as minkw, max(temperature_current_kw) as maxkw
      from ((select t.*
             from temperatures t
             where temperature_value <= ACTUAL_TEMPERATURE
             order by temperature_value desc
             limit 1
            ) union
            (select t.*
             from temperatures t
             where temperature_value >= ACTUAL_TEMPERATURE
             order by temperature_value asc
             limit 1
            ) 
           ) t
     ) t;
R: Interpolate + Extrapolate over borders - with data.table?

R: Interpolate + Extrapolate over borders - with data.table?


By : kopffSchrott
Date : March 29 2020, 07:55 AM
This might help you So, I have the following problem: I have a data set, A (data.table object), of the following structure: , How about something like this.
code :
# please try to make a fully reproducible example!
library(data.table)
df <- fread(input=
"date       days     rate
1996-01-02    9 5.763067
1996-01-02   15 5.745902
1996-01-02   50 5.673317
1996-01-02   78 5.608884
1996-01-02  169 5.473762
1996-01-03    9 5.763067
1996-01-03   14 5.747397
1996-01-03   49 5.672263
1996-01-03   77 5.603705
1996-01-03  168 5.470584
1996-01-04   11 5.729460
1996-01-04   13 5.726104
1996-01-04   48 5.664931
1996-01-04   76 5.601891
1996-01-04  167 5.468961")
df[,date := as.Date(date)]
df <- 
  merge(df,
        expand.grid( days=1L:100L,                   # whatever range you are interested in
                     date=df[,sort(unique(date))] ), # dates with at least one observation
        all=TRUE # "outer join" on all common columns (date, days)
        )
df[, rate := ifelse(is.na(rate),
                    predict(lm(rate~days,.SD),.SD), # impute NA w/ lm using available data
                    rate),                          # if not NA, don't impute
   keyby=date]
head(df,10)
#           date days     rate
#  1: 1996-01-02    1 5.766787 <- rates for days 1-8 & 10 are imputed 
#  2: 1996-01-02    2 5.764987
#  3: 1996-01-02    3 5.763186
#  4: 1996-01-02    4 5.761385
#  5: 1996-01-02    5 5.759585
#  6: 1996-01-02    6 5.757784
#  7: 1996-01-02    7 5.755983
#  8: 1996-01-02    8 5.754183
#  9: 1996-01-02    9 5.763067 <- this rate was given
# 10: 1996-01-02   10 5.750581
setkey(df, date, days)

df2 <- data.table( # this is your framework of date/days pairs you want to evaluate
        expand.grid( date=df[,sort(unique(date))],
                     days=1L:100L),
        key = c('date','days')
)

# average of non-NA values between two vectors
meanIfNotNA <- function(x,y){
  (ifelse(is.na(x),0,x) + ifelse(is.na(y),0,y)) /
    ( as.numeric(!is.na(x)) + as.numeric(!is.na(y)))
}

df3 <- # this is your evaluations for the date/days pairs in df2.
  setnames(
    df[setnames( df[df2, roll=+Inf], # rolling join Last Obs Carried Fwd (LOCF)
                 old = 'rate',
                 new = 'rate_locf' 
               ),
     roll=-Inf], # rolling join Next Obs Carried Backwd (NOCB)
    old = 'rate',
    new = 'rate_nocb'
  )[, rate := meanIfNotNA(rate_locf,rate_nocb)]
# once you're satisfied that this works, you can include rate_locf := NULL, etc.

head(df3,10)
#          date days rate_nocb rate_locf     rate
#  1: 1996-01-02    1  5.763067        NA 5.763067
#  2: 1996-01-02    2  5.763067        NA 5.763067
#  3: 1996-01-02    3  5.763067        NA 5.763067
#  4: 1996-01-02    4  5.763067        NA 5.763067
#  5: 1996-01-02    5  5.763067        NA 5.763067
#  6: 1996-01-02    6  5.763067        NA 5.763067
#  7: 1996-01-02    7  5.763067        NA 5.763067
#  8: 1996-01-02    8  5.763067        NA 5.763067
#  9: 1996-01-02    9  5.763067  5.763067 5.763067  <- this rate was given
# 10: 1996-01-02   10  5.745902  5.763067 5.754485
Related Posts Related Posts :
  • How to check if an axes handle is cleared or not
  • How to select from two identical bus signals in Simulink?
  • Colormap three colors
  • plot3 for display three dimension data in matlab
  • In MATLAB How to calculate a time between two dates with a custom format?
  • How to make a formula in a MATLAB figure on the y-axis bold along with LaTeX interpreter?
  • Maltab: copy axes in a gui to a figure
  • how to find close value of matrix using matlab
  • Poor performance for SVM for unbalanced dataset- how to improve?
  • RGB image compression using SVD
  • How to output a function with numeric inputs evaluated?
  • What is the fastest way to compare vectors from 3D array in matlab?
  • Matlab fprintf output is not appearing in command window with no error?
  • Izhikevich Neuron model - equations
  • Keeping whitespace in csv headers (Matlab)
  • Get legend right with stacked bar plot
  • 'No supported GPU device was found on this computer' Matlab R2018a?
  • Calculate the contact length between segments of image in Matlab
  • How to add legend elements in Matlab in the plot itself
  • Using streamslice/quiver and inpolygon crop
  • How to best set date axis in Matlab
  • Finding a certain value below the maxima in Matlab
  • In MATLAB, How I can run multiple files .m (M-file) automatically?
  • how to Display data in matrix with with more than 4 decimals
  • Maximum array size in MATLAB?
  • Reducing Mean Square Error
  • What do I have to add at the beginning of this loop?
  • Matlab Error: ??? Cell contents reference from a non-cell array object
  • MATLAB combining edge region back into image
  • To find points of intersection between straight lines & our figure in matlab
  • How to use a cross validation test with MATLAB?
  • Loading multiple images in MATLAB
  • how to convert the spectrogram into an image
  • shadow
    Privacy Policy - Terms - Contact Us © bighow.org