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

Walter Roberson
Walter Roberson 2020년 7월 11일
textscan with CommentStyle option
dpb
dpb 2020년 7월 11일
readtable and readmatrix also support 'CommentStyle' and are hgher-level than textscan

댓글을 달려면 로그인하십시오.

 채택된 답변

Govind KP
Govind KP 2020년 7월 14일

0 개 추천

You can use readmatrix function as follows:
>> nodes = readmatrix('nodes.csv', 'CommentStyle','#')

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

제품

릴리스

R2020a

질문:

2020년 7월 11일

댓글:

2020년 7월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by