To link string of one .txt file to a value of another?

1 visualización (últimos 30 días)
Corneel Lootens
Corneel Lootens el 7 de Sept. de 2022
Respondida: chrisw23 el 7 de Sept. de 2022
I have 2 .txt files
One with a value and a string (class) and one with values.
Example: 1.txt
1 "classCar"
2 "classBicycle"
3 "classFoot"
Example: 2.txt
10 1
20 2
30 3
How can I get the value linked with "classBicycle" and compare it with 2.txt to get the value with 2 (20)?
Thanks for the help!

Respuesta aceptada

chrisw23
chrisw23 el 7 de Sept. de 2022
defLines = readlines("1.txt").replace("""","").split;
rawLines = readlines("2.txt").split;
defTbl = array2table(defLines,"VariableNames",["classId" "className"]);
rawTbl = array2table(rawLines,"VariableNames",["value" "classId"]);
resStruct.className = rawTbl.classId.replace(defTbl.classId,defTbl.className);
resStruct.value = rawTbl.value;
resStruct.classId = rawTbl.classId;
struct2table(resStruct) % linked for access
another option would be the use of an enumeration class

Más respuestas (0)

Categorías

Más información sobre Data Import and Export en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by