Vlookup technique in Matlab

조회 수: 6 (최근 30일)
Vespi
Vespi 2016년 3월 17일
댓글: Walter Roberson 2016년 3월 17일
I have:
  1. Single column array that I converted to table in matlab, which represent RGB values combined in one cell so 255119255 (RRRGGGBBB) -Note: this has 40448352 rows
  2. Imported table with 10 columns. Column 2 defines the object corresponding to the RGB combined value also 255119225 format (column 9) - Note: This has about 60 rows
I would like to find each cell value in table (1) and if there is a match to the value in Table 2, Column 9 I want it to give me the name corresponding to that value (found in Table 2 column 2). If no match then 'NAN'.
Thank you!

채택된 답변

Walter Roberson
Walter Roberson 2016년 3월 17일
[tf, idx] = ismember(table1.Column1, table2.Column9);
results = repmat({'NaN'}, length(tf), 1); %did you say 'NaN' or NaN ?
results(tf) = table2.Column2(idx(tf));
You will need to adjust for the appropriate column names.
  댓글 수: 2
Vespi
Vespi 2016년 3월 17일
편집: Vespi 2016년 3월 17일
I wanted NAN in order to represent no match. Ideally I would like to get the nearest value since the RGB combination should represent an object.
I ran the code and cannot figure out the last line
results(tf) = table2.Column2(idx(tf));
I changed it to results(tf) = Object(idx(tf)); Where object is the name of the column from which I want the object values to be given for the corresponding RGB value.
Walter Roberson
Walter Roberson 2016년 3월 17일
You cannot just name a column, you have to name the table as well, like table2.Object
I am not clear as to whether your Object column is numeric or string?
You need to define "nearest", which is something that is not straight forward in colour.

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

추가 답변 (1개)

Kelly Kearney
Kelly Kearney 2016년 3월 17일
My vlookup function does this (using the same method Walter describes, in a nice little wrapper).

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by