interpolation

“Nearest neighbor”-like interpolation in MATLAB

这一生的挚爱 提交于 2019-12-23 17:41:08
问题 This is a small thing but has been bothering me for a while now, so I thought I would let the crowd solving begin :) I have a matrix with timestamps and a corresponding logical value (or 1/0), i.e. of = [-inf 0 10 15 190 inf; 1 0 0 1 1 0]' and an another time vector, e.g. t = 0:0.1:1e3; or whatever, you get the point :) Now how do I (read: would you) inter-/extrapolate the logical infomation in of so it matches the timestamps in t , but with the interpolated logicals always assuming the last

How to improve performance of this linear interpolation

点点圈 提交于 2019-12-23 16:43:25
问题 For a given column in a dataframe, I want to construct a new vector which for each point consists of the average of the points on either side. However for the last observation it will instead be the second to last. And for the first observation it will be second. I wrote this R code to solve the issue, however I am calling it repeatedly and it is extremely slow. Can someone give some tips on how to do it more efficiently? Thanks. x1 <- c(rep('a',100),rep('b',100),rep('c',100)) x2 <- rnorm(300

Collapsing a 10 period curve to 4 periods

给你一囗甜甜゛ 提交于 2019-12-23 14:39:34
问题 I have a 10 period cost curve table below. How do I programmatically collapse/condense/shrink this to 4 periods. I'm using VBA but I should be able to follow other languages. The routine should work for whatever period you pass to it. For example, if I pass it a 7 it should condense the percentages to 7 periods. If I pass it 24 then expand the percentages to 24 periods, spreading the percentages based on the original curve. Any help or example will be appreciated. Thanks... ORIGINAL Period

Collapsing a 10 period curve to 4 periods

旧街凉风 提交于 2019-12-23 14:39:06
问题 I have a 10 period cost curve table below. How do I programmatically collapse/condense/shrink this to 4 periods. I'm using VBA but I should be able to follow other languages. The routine should work for whatever period you pass to it. For example, if I pass it a 7 it should condense the percentages to 7 periods. If I pass it 24 then expand the percentages to 24 periods, spreading the percentages based on the original curve. Any help or example will be appreciated. Thanks... ORIGINAL Period

Equally spaced points in a contour

不想你离开。 提交于 2019-12-23 12:56:13
问题 I have a set of 2D points (not ordered) forming a closed contour, and I would like to resample them to 14 equally spaced points. It is a contour of a kidney on an image. Any ideas? 回答1: One intuitive approach (IMO) is to create an independent variable for both x and y . Base it on arc length, and interpolate on it. % close the contour, temporarily xc = [x(:); x(1)]; yc = [y(:); y(1)]; % current spacing may not be equally spaced dx = diff(xc); dy = diff(yc); % distances between consecutive

Equally spaced points in a contour

混江龙づ霸主 提交于 2019-12-23 12:55:28
问题 I have a set of 2D points (not ordered) forming a closed contour, and I would like to resample them to 14 equally spaced points. It is a contour of a kidney on an image. Any ideas? 回答1: One intuitive approach (IMO) is to create an independent variable for both x and y . Base it on arc length, and interpolate on it. % close the contour, temporarily xc = [x(:); x(1)]; yc = [y(:); y(1)]; % current spacing may not be equally spaced dx = diff(xc); dy = diff(yc); % distances between consecutive

Save scipy object to file

不羁的心 提交于 2019-12-23 12:49:24
问题 I want to save the object interpolator generated from scipy.interpolate.InterpolatedUnivariateSpline to a file, in order to load it afterwards and use it. This is the result on the console: >>> interpolator <scipy.interpolate.fitpack2.InterpolatedUnivariateSpline object at 0x11C27170> np.save("interpolator",np.array(interpolator)) >>> f = np.load("interpolator.npy") >>> f array(<scipy.interpolate.fitpack2.InterpolatedUnivariateSpline object at 0x11C08FB0>, dtype=object) These are the results

gnuplot - smooth interpolation x=f(y)

廉价感情. 提交于 2019-12-23 10:08:39
问题 I would like to plot a 2D graph with csplines interpolation of my data with an independent variable on y axis. The interpolating function should be in x = f(y) form. Is there any way to do this without switching axes? gnuplot: set terminal svg size 400,300 enhanced fname 'arial' fsize 10 butt solid set output 'out.svg' set xrange [10:13] plot "data.txt" using 2:1 notitle #smooth csplines Data: 1 11.45294118 2 11.43529412 3 11.18823529 4 10.98235294 5 10.94117647 6 11.28823529 7 11.27058824

How to get special derivative from an interpolated function

烈酒焚心 提交于 2019-12-23 04:50:13
问题 I have created a h5 file for a simple cube and then read it by python and finally use RegularGridInterpolator function to interpolate. Everything works perfectly for me. But, I want to know how can I change my code so that, I can get derivative from this interpolated function? For your kind information, I have given here my code: code for creating h5 file import numpy as np import h5py def f(x,y,z): return 2 * x**3 + 3 * y**2 - z x = np.linspace(-1, 1, 2) y = np.linspace(-1, 1, 2) z = np

Draw heat map (or similar) of 2D population distribution

╄→гoц情女王★ 提交于 2019-12-23 02:34:41
问题 I am wondering how I can draw an image of the population proportion (pop.prop) at these locations (x and y) so that I can see the population distribution clearly? The data is shown below: pts.pr = pts.cent[pts.cent$PIDS==3, ] pop = rnorm(nrow(pts.pr), 0, 1) pop.prop = exp(pop)/sum(exp(pop)) pts.pr.data = as.data.frame(cbind(pts.pr@coords, cbind(pop.prop))) x y pop.prop 3633 106.3077 38.90931 0.070022855 3634 106.8077 38.90931 0.012173106 3756 106.3077 38.40931 0.039693085 3878 105.8077 37