How do I ensure that the number of delimiters on each row are constant when reading a hige csv file
15 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have a huge csv file using comma. Using the readtable function, I keep getting the error message: ''All lines of a text file must have the same number of delimiters.''.
rawdata = readtable(filename, 'Delimiter', ',');
How can I ensure that each row has the same number of delimiters?
4 comentarios
Masood Anzar
el 18 de Abr. de 2020
How to handle if the any row of column is blank
I have a table containing data like 't=1139692479071' in each row of first column.
But some of the row are blank. I want to split the data using '=' as separator.
When I run this command ===> split(T{:,1},'=')
This error is coming : Element 2687 of the text contains 0 delimiters while the previous elements have 3.
All elements must contain the same number of delimiters.
Please advice me how to apply delimiter if the data have blank elements. I cannot remove blank rows as there is data in other columns also.
dpb
el 18 de Abr. de 2020
You'll still have to either
- Insert a dummy text into blank rows like 'T=nan'
- Or only select the rows that have the delimiter to split
logical addressing/indexing is your friend in such cases.
Respuestas (1)
Viren Gupta
el 24 de Sept. de 2018
Making sure that each line of the input file has same number of delimiters is what the person who created this file has to do. You can only check if each line of the file has same number of delimiters. For this, you can use 'fgets()' function which gives you a string and then use 'strsplit' function based on ',' as your delimiter and then check the size of the cell array returned. If all such cells have same size, then each row has same number of delimiters else not.
0 comentarios
Ver también
Categorías
Más información sobre Text Files en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!