Azzera filtri
Azzera filtri

Extrapolate or copy map values outward to replace zeros in 2D array

9 visualizzazioni (ultimi 30 giorni)
I have some code setup to evaluate timeseries data - three channels of data: speed, flow, pressure. This data is generated by a system that monitors speed and flow, then makes a determination of pressure based on those parameters. Unfortunately I do not have access to the logic that converts speed/flow in to a pressure command.
Using a meshgrid and griddedData commands, I can reverse engineer a "map" that reflects this time series data. An example of this map is shown in the attached image. The actual map is much larger - thousands of rows/columns to provide more resolution - while the image below is reduced for simplicity.
The problem I am facing is that the only cells populated (for pressure) are at speed/flow combinations that have been observed in transient evaluated to make the map. When this map is then applied over additional data sets, there are intermittent zeros when an evaluated speed/flow point has no data in the map.
Example: Speed: 18, flow: 6 = 0. In reality, this system would have likely selected a pressure of approximately 180, similar to the cell just to the left. There are not normally large discontinuities in this data. I would like to be able to "extend" this reverse-engineered map 'outward' in all direction to account for future data that could be slightly outside the previously evaluated data.
A couple different methods would work: (1) extrapolate outward based on trends of existing data, (2) direct copy/paste of the neighboring cells for "X" number of rows/columns 'outward'
A challenge is that for different systems, this map shape can vary drastically. Sometimes the populated cells are as shown - with a 'vertical' edge at speed 17. Other times the map could be much wider, spreading to speed 26, but less flow, maybe stopping at 25 or 30.
While a "brute force" method to find zeros around the populated cells could probably be deployed, it does seem like there must be a surface/gridding method that could help. I've yet to find something in all my searching.
Thanks in advance for your help!

Risposta accettata

Rishav
Rishav il 3 Mag 2023
Modificato: Rishav il 4 Mag 2023
Hi Ryan,
It sounds like you're trying to perform interpolation and/or extrapolation to fill in the gaps in your time series data. There are a number of different methods you can use to accomplish this, but one approach that might work well for your application is to use a technique known as "multivariate spline interpolation".
In brief, the idea behind multivariate spline interpolation is to fit a smooth, continuous function to your data that passes through all of your observed data points. This function can then be evaluated at any arbitrary point within the domain of your data (i.e., any speed/flow combination), allowing you to estimate the corresponding pressure value.
Here is the MATLAB code to implement multivariate spline interpolation:
% Assume you have three arrays: speed, flow, and pressure
% representing your time series data
% Define the grid of points where you want to interpolate the pressure values
new_speed = linspace(min(speed), max(speed), 100);
new_flow = linspace(min(flow), max(flow), 100);
[new_speed_grid, new_flow_grid] = meshgrid(new_speed, new_flow);
% Define the function that will perform the interpolation
rbf = scatteredInterpolant(speed(:), flow(:), pressure(:), 'linear', 'none');
% Evaluate the function at the new points to get the interpolated pressure values
new_pressure = rbf(new_speed_grid, new_flow_grid);
% Plot the interpolated pressure values as a surface
surf(new_speed_grid, new_flow_grid, new_pressure);
xlabel('Speed');
ylabel('Flow');
zlabel('Pressure');
In this example, new_pressure will be a 2D array representing the interpolated pressure values at the new speed/flow combinations defined by new_speed_grid and new_flow_grid. The scatteredInterpolant function is used to define the interpolation function, and the 'linear' option specifies that a linear interpolation should be used. The 'none' option specifies that the interpolation should not enforce any boundary conditions, which may be appropriate for your data. The surf function is used to plot the interpolated pressure values as a surface, with the speed and flow values on the x and y axes, and the pressure values on the z axis.
Regards,
Rishav Saha

Più risposte (0)

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Prodotti


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by