Info
Questa domanda è chiusa. Riaprila per modificarla o per rispondere.
Taking peices out of a sentence
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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!
0 Commenti
Risposte (1)
Image Analyst
il 26 Giu 2017
Modificato: Image Analyst
il 26 Giu 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.
0 Commenti
Questa domanda è chiusa.
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!