필터 지우기
필터 지우기

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

조회 수: 6 (최근 30일)
Robert
Robert 2015년 6월 16일
답변: Walter Roberson 2015년 6월 17일
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
James Tursa
James Tursa 2015년 6월 16일
Please post a short example showing the input data set and the result you are looking for.

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2015년 6월 17일
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.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by