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

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 件のコメント

Yatharth
Yatharth 2022 年 6 月 22 日
編集済み: Yatharth 2022 年 6 月 22 日
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

サインインしてコメントする。

回答 (1 件)

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

製品

リリース

R2021b

質問済み:

2022 年 6 月 21 日

回答済み:

2022 年 6 月 27 日

Community Treasure Hunt

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

Start Hunting!

Translated by