Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
Taking peices out of a sentence
조회 수: 1 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Image Analyst
2017년 6월 26일
편집: Image Analyst
2017년 6월 26일
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
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!