About copying txt to matrix
1 次查看(过去 30 天)
显示 更早的评论
Hello,
I have a.txt file like this;
0.0 1548.52 /
200.0 1530.29 /
250.0 1526.69 /
400.0 1517.78 /
600.0 1509.49 /
800.0 1504.30 /
1000.0 1501.38 /
1200.0 1500.14 /
1400.0 1500.12 /
1600.0 1501.02 /
1800.0 1502.57 /
2000.0 1504.62 /
2200.0 1507.02 /
2400.0 1509.69 /
2600.0 1512.55 /
2800.0 1515.56 /
3000.0 1518.67 /
3200.0 1521.85 /
3400.0 1525.10 /
3600.0 1528.38 /
3800.0 1531.70 /
4000.0 1535.04 /
4200.0 1538.39 /
4400.0 1541.76 /
4600.0 1545.14 /
4800.0 1548.52 /
5000.0 1551.91 /
and I want to copy that to a matrix which has 2 columns and and rows that equal to number of lines. I would be grateful if you help. Thank you.
0 个评论
采纳的回答
Walter Roberson
2020-8-6
filename = 'whatever.txt';
fid = fopen(filename, 'rt');
data = cell2mat( textscan(fid, '%f%f%*s') );
fclose(fid);
更多回答(1 个)
Sudheer Bhimireddy
2020-8-6
Try this:
Look at the examples given there you should be able to do it in the similar manner.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Text Data Preparation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!