Ignore comments in a csv file
14 ビュー (過去 30 日間)
古いコメントを表示
I have a .csv file that reads as the following:
# nodes.csv file for V-REP kilobot motion planning scene.
# All lines beginning with a # are treated as a comment and ignored.
# Each line below has the form
# ID x y heuristic-cost-to-go
# where ID is the unique integer ID number of the node (1 through N)
# (x y) is the location of the node in the plane and heuristic-cost-to-go
# is an optimistic estimate of the path length from that node to the
# goal node as needed by A* search.
1 -0.5 -0.5 1.4142
2 -0.09 -0.4 1.0762
3 -0.285 -0.305 1.1244
4 0.0575 -0.225 0.8494
5 -0.0525 -0.0175 0.7604
6 -0.37 0.3 0.8927
7 0.3525 -0.0525 0.5719
8 0.0625 0.255 0.5014
9 -0.1 0.3725 0.6134
10 0.4275 0.195 0.3135
11 0.345 0.3525 0.214
12 0.5 0.5 0
The file formatting is not fixed per se and can have multiple lines of comments/nodes when necessary. I realise the csvread() function does not ignore the comments. Can someone suggest a suitable snippet to ignore comments and extract numbers from the .csv file? I am fairly new to programming with Matlab and would appreaciate any help.
2 件のコメント
dpb
2020 年 7 月 11 日
readtable and readmatrix also support 'CommentStyle' and are hgher-level than textscan
採用された回答
Govind KP
2020 年 7 月 14 日
You can use readmatrix function as follows:
>> nodes = readmatrix('nodes.csv', 'CommentStyle','#')
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Text Files についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!