Filtering, renaming and identifying similar values using two tables.

2 次查看(过去 30 天)
The objective of this exercise is to find/match vehicle IDs and rename those IDs to a string "AV" or "DV". Below is a detailed outline of my steps:
In summary this is what I want to achieve:
Step 1: I would like to search Table 2 for the values in Table 1
TABLE 1 TABLE 2
Step 2: Once similar values are found, I would like the "Similar" values identified in coloumns "FirstVID" and "SecondVID" to be updated with the words "AV".
I would like this to update Table 2. As opposed to generating a different table for only FirstVID and SecondVID. In other words the table would appear like:
A similar process of matching should taken to rename the other FIRSTVIDs (eg 1348) to "DVs".
I would like this one table - Varibales have the AV and DV names fill the FirstVID and SecondVID. I would like to keep it as a TABLE in Matlab and not a string.
----------------------------------
The assistance from the community so far has allowed me to generate various tables where matching values replaced the ID with "AVs".
Example of the code:
[~, ~, ib1] = intersect(AV1.VehNo,NewTab.FirstVID)
[~, ~, ib2] = intersect(AV1.VehNo,NewTab.SecondVID)
FirstVIDAV = num2cell(NewTab.FirstVID);
SecondVIDAV = num2cell(NewTab.SecondVID);
FirstVID(ib1) = {'AV'}
SecondVID(ib2) = {'AV'}
However, this code generated different tables and did not change the values in the original table.
Any assistance would be greatly appreciated. Please note that the data set I am using a very large, over 3000 rows.
  1 个评论
Peter Perkins
Peter Perkins 2023-4-5
As has been pointed out several times in your other posts, you cannot store text in a numeric variable.
Your choices are to store everything in a cell, such as {"AV"; 1348; 1189; 1607; 1402; "AV"}, which will probably be a disaster, or as I suggested in one of your other posts, treat the IDs as IDS, not as numbers, and store it all as text, such as ["AV"; "1348"; "1189"; "1607"; "1402"; "AV"]. This does not replace the table with a string variable, only one of the variables in the table. To do what you are asking to do, you don't have any other choices. Unless you need to do arithmetic on the IDs, you are not losing anything. You can even sort them (assuming the all four digits, you may need leading zeros).
As far as modifying the original table, just assign back into the variable in the table, not to some other workspace variable.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Cell Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by