Write certain lines of a text file to another text file
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello All--
I have a problem that I could not solve it properly! I have a huge text file, and a single -column matrix. I have sorted this matrix in a ascending way. Each element of this matrix is corresponding to the line number of interest in the text file.
Basically I need to write a code such that the output file will include only the line of interest.
The following is the code I have written but it did not work at all! I do appreciate your helps.
Thanks
% I have tried to make a single-column excel file using the text file!!
filename1 = 'Text.xlsx';
Y = xlsread( filename1, 'A:A');
% This is the matrix containing the line numbers of interest
filename2 = 'Matrix.xlsx';
Z = xlsread( filename2, 'A:A');
Q=zeros(N,0); %N is size of the matrix Z
for i=1:N
Q(i,1) = Y((Z(i,1)),1);
end
xlswrite('newText.xlsx',Q ), % It did not work because my initial text file contains characters, numbers and words. it seems it cannot be transferred to a single-column matrix
0 commentaires
Réponses (1)
Walter Roberson
le 11 Juin 2015
If you have a sufficiently new MATLAB:
readtable() to read in the data, index the table,
subset = TheTable(DesiredRows,:);
and then writetable() to create the new xlsx file.
0 commentaires
Voir également
Catégories
En savoir plus sur Text Files dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!