MATLAB: How to modify a large textfile according to words in another textfile in MATLAB

MATLABmodifymodify-textfileread-textfiletextprocessing

I have 3 large textfiles that are in tab seperated column format:
textfile1:
index1 YAL001C
index2 YAL011W-A
index3 YHR048
......
textfile2:
G1 YHR048
G2 YER109C-A
G3 YDR496C-K
......
textfile3:
G1 G15 0.9
G8 G19 0.8
G2 G20 0.6
......
I want to read every word in textfile3 that starts with G (for example G1) then find its corresponding word at column 2 in textfile2 (i.e YHR048) , then find its corresponding index in textfile1(i.e index3) , next modify textfile3 and replace G1 with index3 ; and do that for all of the words that start with G in textfile3.
is there any way to do so?

Best Answer

It could be as trivial as:
indexword = readtable(textfile1, 'ReadVariableNames', false);
indexword.Properties.VariableNames = {'Index', 'Word'};
gword = readtable(textfile2, 'ReadVariableNames', false);
gword.Properties.VariableNames = {'Gcode', 'Word'};
gindexword = innerjoin(gword, indexword); %possibly a simple join would work instead of an innerjoin
t3 = readtable(textfile3, 'ReadVariableNames', false);
t3.Properties.VariableNames = {'Gcode', 'something', 'somethingelse'};
fulltable = join(t3, gindexword)