Textscan with multiple delimiters
Mostrar comentarios más antiguos
I want to read a text file into a cell array so that i have each line of my file as a new row and each attribute in my file as a column on that row.
file = fopen('file.txt');
d = textscan(file,'%s %d %d %d ,'delimiter',',');
If i run the code above it gives me a 1 x n array. If i type d{1} i get the first character of every line. Similarly if i type d{2} i get the second attribute of every line. Instead of having 1 x the number of attributes i would like the number of lines x the number of attributes so i can easily. Retrieve the values i need.
I asked a similar question yesterday but that gave me 2 separate arrays where i want all of this to be stored in the same cell array.
I have also tried this as my delimiter but it tells me the Delimiter must be a string.
'delimiter',{',','\n'}
1 comentario
Cedric
el 21 de Oct. de 2013
Could you attach your data file or part of it?
Respuesta aceptada
Más respuestas (1)
per isakson
el 21 de Oct. de 2013
Editada: per isakson
el 21 de Oct. de 2013
I'm not sure I understand your question, but:
textscan( '1,2;3:4', '%d%d%d%d', 'Delimiter', ',;:' )
ans =
[1] [2] [3] [4]
>>
Categorías
Más información sobre Cell Arrays en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!