Read specific column in .txt file
91 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(2 个)
KSSV
2021-12-4
T = readtable('myfile.txt') ; % also read about load, importdata, textscan
x = T.(1) ;
y = T.(2) ;
plot(x,y)
0 个评论
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Large Files and Big Data 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!