Filtering, renaming and identifying similar values using two tables.
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1338634/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1338639/image.jpeg)
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1338644/image.jpeg)
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 Commento
Peter Perkins
il 5 Apr 2023
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.
Risposte (0)
Vedere anche
Categorie
Scopri di più su Shifting and Sorting Matrices in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!