Replace values in matrix with values based on look up table, without loop?

8 vues (au cours des 30 derniers jours)
Robert
Robert le 16 Juin 2015
I'm new to this type of data manipulation, I have a large matrix with a set of values which I would like to convert to different values based on a table. I did a search for lookup tables, but did not find functions readily, is this something that requires one of the tool boxes? Thanks!
Talbot
  1 commentaire
James Tursa
James Tursa le 16 Juin 2015
Please post a short example showing the input data set and the result you are looking for.

Connectez-vous pour commenter.

Réponses (1)

Walter Roberson
Walter Roberson le 17 Juin 2015
mapfrom = [2.8 19 -3 pi 42 1];
mapto = [5 6 2 41 -pi 7];
%we need to get them in sorted order
[sortfrom, sortidx] = sort(mapfrom);
sortto = mapto(sortidx);
Now to look up,
MappedValues = interp1(sortfrom, sortto, ValuesToLooKUp, 'nearest');
The 'nearest' is not needed if all of the original values and all of the values to look up are integers, but if any of them are floating point then you need it because floating point values often differ in the last bit or two from what you think they are.

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by