![]() Also, if you do get it to work, but it doesn't speed things up much, I'd be very interested to know that, so please post the result here. Let me know if you can't get it to work and I'll try and put together something more explicit once I get home. You may be able to simply replace with and of course, adjust the inputs to cellfun appropriately. Then the call to cellfun applies the sum function to each cell in VCell, and returns the result in A. The mat2cell function converts V to a cell column vector, where each cell contains a row of V. But I think the method I've used extends to your situation. ![]() ![]() Of course, what I've done is equivalent to sum(V, 2). VCell = mat2cell(V, ones(NumRow, 1), NumCol) It seems to me that you can get rid of the explicit loop using mat2cell and cellfun.Ī simple example of what I mean is as follows: NumRow = 4 Having said that, since the iterations of your loop do not depend on each other, vectorization should be possible. interpolating a function like that seems a waste of time though as sin (x) itself will do the interpolation job. 'spline' or 'pchip' will provide some difference. I'm at work and so don't have time to familiarize myself with interp1 (I've never used it before), so if the following answer is inappropriate, I apologize in advance. If you add in 3 points between every pair of points and then linearly interpolate you will just get extra points on the same lines that you had before. ![]() It will likely grow with system size due to a more efficient memory bandwidth utilization. El vector xq contiene las coordenadas de los puntos de consulta. El vector x contiene puntos de muestra y v contiene los valores correspondientes, v ( x ). The following version is around 20% faster on my computer for N=1000, S=10000 and TI of 10000 elements. vq interp1 (x,v,xq) devuelve valores interpolados de una funcin 1D en puntos de consulta especficos utilizando la interpolacin lineal. Hence, I would suggest you transpose your matrices in your entire code, unless of course you rely on this exact data layout somewhere else for performance reasons.Įdit Because of the column layout of matrices your original code can be improved by transposing the matrices and working column-wise. If you pass V as an SxN matrix it potentially allows for more efficient parallelization of interp1, since all CPUs can access the memory in a more efficient manner. This is because MATLAB stores matrices column-wise (columns are contiguous in memory). Numeric vector points at which to compute the interpolation all points must lie between min (x) and max (x). Numeric vector values of the assumed underlying function x and y must be of the same length. Here you have to transpose V since interp1 interpolates within columns. Numeric vector points on the x-axis at least two points require will be sorted if necessary. If on the other hand the measurements have been taken at the same times for different values of N (T is a vector of size S, and not a matrix, or in other words all rows of T are equal) you can interpolate in one call to interp1. You might not need it - it depends on what you later do with the data. It returns a cell of vectors, so the second line makes sure that you have a matrix as output. I know the thread using interp1 in R for matrix but I do not have a matrix.If you have, as you say, different time of measurement for all measurements (T is a matrix and not a vector), you can do what you want with one call to arrayfun as follows: VI = 1:size(V, 1), 'UniformOutput', false) Īrrayfun is similar to a loop, but since it is an internal matlab function it might be faster. # Wanted, MATLAB: u = interp1(u, linspace(1, numel(u), numel(u)-1)) Points 'xi' outside of range of argument 'x'. I am not sure about the second interp1 parameter what is not required in MATLAB so I just let unsuccessufully y 500 k points so linear will work) and its output at the top List of 2Įrror in interp1(x, y, xi, method = "linear") : approx rule=1 is equivalent to MATLAB pseudocode.Pseudocode is u = interp1(u, linspace(1, numel(u), numel(u)-1)) in MATLAB where extrapolation returns NaN if the point is outside the domain (default, more here). I am trying to interpolate linearly in R.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |