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

1 回表示 (過去 30 日間)
Corneel Lootens
Corneel Lootens 2022 年 9 月 7 日
回答済み: chrisw23 2022 年 9 月 7 日
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 Center および File ExchangeLarge Files and Big Data についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by