Split a cell array of character vectors at multiple-number delimiter
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Giuseppe Degan Di Dieco
el 24 de Sept. de 2021
Comentada: Giuseppe Degan Di Dieco
el 27 de Sept. de 2021
Hello Everyone,
I hope that you're doing well, and your loved ones as well.
I wanted to ask you for help, after many trials. The issue is that I'va data on construction types for bridges uploaded from an Excel spreadsheet, and their data type is CELL ARRAY OF CHARACTER VECTORS.
Below, I jotted down a few example lines of these data:
BEAMS-PREFLEX WITH SLAB-RC 4 NO SPANS
ARCH-MASONRY 1 NO STONE (LIMESTONE SADDLED 1924)
ARCH-MASONRY 2 NO SPAN WIDENED WITH SLAB-R.C. 2 NO SPAN
BOX-R.C. 1 NO SPAN
We can see that they've a typical structure, namely the construction system, followed by the superstructure material, and then by the number of spans. However, these different parameters should stay into separated cells.
I'm a beginner of analysing text with computing techiniqeus, so to use the built-in function 'split', I converted the data type into STRING, and then defined a pattern of the number of spans, namely string(1 2 3 4 ...). However, I couldn't save the split text into the variable spl because the for loop doesn't work, and the results obtained from the split function changes for each data line.
For example, for the first dataline I retrieve:
spl, 2x1 string, that is:
BEAMS-PREFLEX WITH SLAB-R.C.
NO SPANS
Then, for the second dataline I retrieve:
spl, 6x1 string, that is:
ARCH-MASONRY
NO SPAN (LIMESTONE SADDLED)
3 WHITE SPACES
)
I also attached my simple code for any advice.
Thanks for your time and consideration, I look forward to hearing from you.
Best.
% T2 is the data table
% T2.ConstructionType = string(T2.ConstructionType)
% str = T2{:, 6}; %T2.ConstructionType is the sixth column of T2
% noOfSpans = [1:1:20]
% pat = string(noOfSpans)
% spl = []; %Initialisation of variable for the split results
% for i = 1:1:length(str)
% spl = split(str(i), pat)
% end
0 comentarios
Respuesta aceptada
Stephen23
el 24 de Sept. de 2021
Editada: Stephen23
el 24 de Sept. de 2021
Rather than telling us what you currently get, it is probably more useful if you tell us what you want.
I made some guesses about how that text is formatted:
str = ["BEAMS-PREFLEX WITH SLAB-RC 4 NO SPANS";...
"ARCH-MASONRY 1 NO STONE (LIMESTONE SADDLED 1924)";...
"ARCH-MASONRY 2 NO SPAN WIDENED WITH SLAB-R.C. 2 NO SPAN";...
"BOX-R.C. 1 NO SPAN"];
tkn = regexp(str,'^(\w+)-(\D+?)\s*(\d+)\s*(.*)','tokens','once');
tkn = vertcat(tkn{:})
Más respuestas (0)
Ver también
Categorías
Más información sobre Characters and Strings 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!