write a loop reading txt files to write a xlsx file with specific strings and numbers
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Micangi
el 4 de Mayo de 2020
Comentada: darova
el 6 de Mayo de 2020
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
0 comentarios
Respuesta aceptada
darova
el 4 de Mayo de 2020
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);
11 comentarios
darova
el 6 de Mayo de 2020
How to know if it's empty cell or not? Do you know where empty cells are?
darova
el 6 de Mayo de 2020
Another attempt
S = dir('input*.txt');
str = {};
num = {};
for k = 1:numel(S)
A = readtable(S(k).name,'delimiter','\t','readVariableNames',false);
str(k) = table2cell(A(3,2));
num(k) = table2cell(A(6,2));
end
num = cell2mat(num);
num(isnan(num)) = 100;
Más respuestas (0)
Ver también
Categorías
Más información sobre Spreadsheets en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!