MATLAB: Write a loop reading txt files to write a xlsx file with specific strings and numbers

loopstringtext filexlswrite

Hello,
I have txt files called: Input_1.txt, Input_2.txt, and so on. In these files I have both numbers and strings.
For example, I have to create a loop in wich I have to select, for each txt file, the string at the position (3,1) (in the attached example the string "hello1" and "hello2"), and the number at the position (5,2)
Then, I want to obtain a xlsx files Output.xlsx in which I have the selected strings in the first column and the selected numbers in the second column.
See please the attached files.
Thank you
S = dir('Input_*.txt');
for k = 1:numel(S)
S(k).name
end

Best Answer

try this
S = dir('Input_*.txt');
str = {};
num = {};
for k = 1:numel(S)
A = importdata(S(k).name);
str{k} = A{3,1};
num{k} = A{5,2}'
end
num = cell2mat(num);