Read specific column in .txt file

137 ビュー (過去 30 日間)
Amir Shahang
Amir Shahang 2021 年 12 月 4 日
回答済み: Yusuf Suer Erdem 2021 年 12 月 4 日

Hi, I have 300*2 txt.file (as X and Y in two columns), I have to separate the first column from the second column and then plot the points. I use dlmread for this but it's doesn't work.

回答 (2 件)

KSSV 2021 年 12 月 4 日
T = readtable('myfile.txt') ; % also read about load, importdata, textscan
x = T.(1) ;
y = T.(2) ;

Yusuf Suer Erdem
Yusuf Suer Erdem 2021 年 12 月 4 日
Hi Amir, try these codes below but make sure you put the 'sample.txt' file that I attached into the same directory. Good luck.
reading = fopen('sample.txt');
formatspec=['%f',repmat('%*f',1,5)]; % 5 represents total columns - 1 the first column
data = textscan(reading,formatspec);
reading = fclose(reading);
data{:} % taking the first column


Help Center および File ExchangeLarge Files and Big Data についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by