I want to export 5 columns from a huge text file with 16 columns and save it as a text file again

2 vues (au cours des 30 derniers jours)
I want to export 5 columns from a text huge text file with 16 columns and save it as a text file again. Can someone help me what function can I use for that. I will appreciate any help in this regards.
  1 commentaire
Yatharth
Yatharth le 22 Juin 2022
Modifié(e) : Yatharth le 22 Juin 2022
Hey , since you are reffering to columns I assume you have .csv instead of a .txt file , you can simply read the file and store it in a table and extract your desired columns either by column name (y) or by indexing (x) and later save it again as csv via writetable function
trainDataFileName = 'training.csv';
trainData = readtable(trainDataFileName);
y = trainData( : , ["Arch" "CTB" "Direct" "EntireTestName"])
x = trainData(: , 1:5)
writetable(x,'filename.csv')
you can reffer to readtable and writetable from the MATLAB Documentation

Connectez-vous pour commenter.

Réponses (1)

Yatharth
Yatharth le 27 Juin 2022
Hey , since you are reffering to columns I assume you have .csv instead of a .txt file , you can simply read the file and store it in a table and extract your desired columns either by column name (y) or by indexing (x) and later save it again as csv via writetable function
trainDataFileName = 'training.csv';
trainData = readtable(trainDataFileName);
y = trainData( : , ["Arch" "CTB" "Direct" "EntireTestName"])
x = trainData(: , 1:5)
writetable(x,'filename.csv')
you can reffer to readtable and writetable from the MATLAB Documentation

Catégories

En savoir plus sur Text Analytics Toolbox dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by