Matching Values from one Table to Another

18 ビュー (過去 30 日間)
Jana Sarran
Jana Sarran 2023 年 3 月 27 日
コメント済み: Joe Vinciguerra 2023 年 3 月 28 日
Hi everyone,
Is there a way from me to match the numbers in two dataset and extract the values in the row?
For instance,
This is my first table:
This is my second table:
What is would like to do---> I would like to search for my second table values in the first table, specifically under "FirstVID" and "SecondVID". Once I have a match of these values, I would like the numbers on "FirstVID" or "SecondVID" to be replaced by the string "AV".
Is this posssible?
Thank you.

採用された回答

Walter Roberson
Walter Roberson 2023 年 3 月 27 日
Change
FirstVID = NewTab (:,["FirstVID"])
to
FirstVID = NewTab {:,["FirstVID"]};
  1 件のコメント
Jana Sarran
Jana Sarran 2023 年 3 月 27 日
Thank you!. It worked.

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

その他の回答 (1 件)

Joe Vinciguerra
Joe Vinciguerra 2023 年 3 月 27 日
Veh = [2007; 1265; 1266; 1269];
FirstVID = [1881; 1269; 2007];
SecondVID = [1892; 2188; 1266];
T = table(FirstVID, SecondVID);
% find data common to each table
[~, ~, ib1] = intersect(Veh, T.FirstVID);
[~, ~, ib2] = intersect(Veh, T.SecondVID);
% Convert to cell since you want mixed data types
T.FirstVID = num2cell(T.FirstVID);
T.SecondVID = num2cell(T.SecondVID);
% using the indexing found above, replace with "AV"
T.FirstVID(ib1) = {'AV'};
T.SecondVID(ib2) = {'AV'};
disp(T)
FirstVID SecondVID ________ _________ {[1881]} {[1892]} {'AV' } {[2188]} {'AV' } {'AV' }
Alternately, you could avoid converting to cells and simply repalce the indexed values with NaN, unless having it read "AV" is necessary.
  2 件のコメント
Jana Sarran
Jana Sarran 2023 年 3 月 27 日
Thank you for the help.
I tried using this code but I am getting an error message.
Please see the attached pdf document for the message.
It says that there is an error using Tabular/Intersect
Joe Vinciguerra
Joe Vinciguerra 2023 年 3 月 28 日
Glad you were able to resolve your error in the other thread. Please accept my answer.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by