フィルターのクリア

VLookup Multiple Conditions if statements

6 ビュー (過去 30 日間)
James
James 2020 年 3 月 27 日
編集済み: Adam Danz 2020 年 3 月 31 日
Hi
I was wanting to modify this code to perform a VLookup on 2 columns and return the element of one of the correspoding column element in the same row?
Can someone please assist me on the if statements for this function?
Here is a function I found on Mathworks that I would like to modify: So instead of having one lookup column I need 2.
  7 件のコメント
James
James 2020 年 3 月 30 日
Hi Adam,
The array could be either a cell array or table. Is this a problem for coding?
Thanks so much.
Adam Danz
Adam Danz 2020 年 3 月 30 日
編集済み: Adam Danz 2020 年 3 月 30 日
See updated answer.

サインインしてコメントする。

採用された回答

Adam Danz
Adam Danz 2020 年 3 月 27 日
編集済み: Adam Danz 2020 年 3 月 30 日
No need for a function.
See inline comments for details.
Matrices
% Define matrix
m = randi(3,2000,5);
% Define search variables
lookupValues = [1,3]; % values to search for in the two columns
lookupColumns = [2,3]; % two column numbers to search in
returnColumn = 1; % the column number used to return the output
% Compute outputs (same variable names as the function you shared)
index = ismember(m(:,lookupColumns), lookupValues, 'rows');
content = m(index, returnColumn);
Cell arrays
Look up the value of 2 in column 1 and 'Day' in column 2:
idx = [C{:,1}]'==2 & strcmpi(C(:,2), 'Day');
C(idx,3) % or [C{idx, 3}]
Tables
Look up the value of 2 in column 1 and 'Day' in column 2:
idx = [T{:,1}]==2 & strcmpi([T{:,2}], 'Day');
T(idx,3) % or [T{idx, 3}]
  9 件のコメント
James
James 2020 年 3 月 31 日
Hi Adam,
Could you help me with plotting?
Adam Danz
Adam Danz 2020 年 3 月 31 日
編集済み: Adam Danz 2020 年 3 月 31 日
What are you plotting? If it's a quick question with a straightforward answer, I can help you here. If the question is more in depth, you may want to write a new question and leave a comment with the URL.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Identification についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by