Optimizing indirect mapping: From matrix elements to vector values
Ältere Kommentare anzeigen
I have a 2-D matrix of values, M. There are also two vectors:
- Grid - holds values which are close to the values in M. The values in Grid are essentially "the same" values in M, just might be slightly different (by 0.001 for example).
- Density - For each value of Grid, there is a corresponding density value.
For each element in the matrix: I need to find its density based on the closest value in Grid.
The following code achieves that, but is slow:
function [ density ] = get_density(x, Density, Grid)
[~, min_diff_idx] = min( abs( x - Grid ) );
density = Density( min_diff_idx );
end
M_new = arrayfun( @(x) get_density(x, Density, Grid), M);
Idea for improvement ?
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Optimization Analysis finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!