Borrar filtros
Borrar filtros

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

6 visualizaciones (últimos 30 días)
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 comentario
James Tursa
James Tursa el 16 de Jun. de 2015
Please post a short example showing the input data set and the result you are looking for.

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 17 de Jun. de 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.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by