Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

Taking peices out of a sentence

1 visualización (últimos 30 días)
Vasko Nechev
Vasko Nechev el 26 de Jun. de 2017
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
Could anyone help me figure out how to do this?
I have a large doc full of sentences in the exact format of (1). I need to create a loop that will take (1) and turn it into (2) over and over.
I have no problem creating the loop I just don't know how to select the number from the first part out of the sentence (number always has same length and position).
(1) DD 11011 WELD TO BIKE FRAME
(2) blahblah = *"DD 11011 WELD TO BIKE FRAME"* new line then tab once *"DD11011"* blahblahblah
And finally I'm am not totally sure if matlab has a tab option with fprintf?
Thanks so much for any help!

Respuestas (1)

Image Analyst
Image Analyst el 26 de Jun. de 2017
Editada: Image Analyst el 26 de Jun. de 2017
If thisLine is your line of text and there are spaces around the number, try this inside your loop:
thisLine = 'DD 11011 WELD TO BIKE FRAME' % Changes on each loop iteration.
spaceLocations = find(thisLine == ' ')
letterCode = thisLine(1:spaceLocations(1)-1)
numberCode = thisLine(spaceLocations(1)+1:spaceLocations(2)-1)
fprintf('blahblah = "%s"\n\t"%s%s" blahblahblah\n', thisLine, letterCode, numberCode);
Or if the letters always go from index 1 to 2, and the numbers from index 4 to 8, you could simplify it to
thisLine = 'DD 11011 WELD TO BIKE FRAME'
fprintf('blahblah = "%s"\n\t"%s%s" blahblahblah\n', thisLine, thisLine(1:2), thisLine(4:8));
but the first code is probably more robust.

La pregunta está cerrada.

Community Treasure Hunt

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

Start Hunting!

Translated by