Separate one column into 3 when finding a character
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Mohamed Gamal
el 11 de Oct. de 2017
Comentada: Mohamed Gamal
el 14 de Oct. de 2017
I have one column line but huge data >400,000 points separated by a character /& like this
1
2
3
4
/&
5
6
7
8
/&
9
10
11
12
/&
I want to split this one column into three columns stops at the separator/& like :
1 5 9
2 6 10
3 7 11
4 8 12
0 comentarios
Respuesta aceptada
OCDER
el 11 de Oct. de 2017
Editada: OCDER
el 12 de Oct. de 2017
New Answer:
FID = fopen('data.txt');
T = fscanf(FID, '%f');
fseek(FID, 0, 'bof');
Data = fscanf(FID, [repmat('%f\n', 1, length(T)) '/&'], [length(T) Inf]);
fclose(FID);
Old Answer:
FID = fopen('data.txt', 'r');
Data = fscanf(FID, '%f\n%f\n%f\n%f\n/&', [4 Inf])
fclose(FID);
Data =
1 5 9
2 6 10
3 7 11
4 8 12
3 comentarios
OCDER
el 12 de Oct. de 2017
Hi Mohamed, try the new answer and see if this works. It uses the first scan to determine how many entries there are until the first non-double character (/&), and then uses that information to read in all the data into a Mx3 array.
Más respuestas (0)
Ver también
Categorías
Más información sobre Whos 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!