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

1 次查看(过去 30 天)
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!

采纳的回答

chrisw23
chrisw23 2022-9-7
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Import and Export 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by