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 comentarios

Walter Roberson
Walter Roberson el 11 de Jul. de 2020
textscan with CommentStyle option
dpb
dpb el 11 de Jul. de 2020
readtable and readmatrix also support 'CommentStyle' and are hgher-level than textscan

Iniciar sesión para comentar.

 Respuesta aceptada

Govind KP
Govind KP el 14 de Jul. de 2020

0 votos

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

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Centro de ayuda y File Exchange.

Productos

Versión

R2020a

Preguntada:

el 11 de Jul. de 2020

Comentada:

el 14 de Jul. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by