Picking out a specific string within a string variable.

I have string variable of decimal numbers with spaces in between each...
HoldingLine = 10 78 984182400 2750 0.1224 0.1873 0.2511 0.2340 0.1406 0.0646 380 0.1341 0.1877 0.2494 0.2236 0.1251 0.0544 40 40 40 40 5.1 5.1 5.1 5.1 9.4 9.4 9.4 9.4 9.6 9.6 9.6 9.6 2.7 2.7 2.7 2.7 40 40 40 40 63 50 63 62 3.3 3.3 3.3 3.3 37 37 37 37 5.0 5.0 5.0 5.0 71 71 72 72 3.3 3.3 3.3 3.3
I used the following to get an array of all the 'space' locations...
Position=find(isspace(HoldingLine));
This outputs the following (which gives me the location of my zeros)...
Position =
Columns 1 through 15
3 6 16 21 28 35 42 49 56 63 67 74 81 88 95
Columns 16 through 30
102 109 112 115 118 121 125 129 133 137 141 145 149 153 157 ......
Now I want to print a specifc number in HoldingLine, such as the third number phrase (984182400). Any ideas on how to print just that number (and other specific numbers) from the variable HoldingLine. I see that you can use fseek and fread to do this from a text file, but this is a variable.

 채택된 답변

Walter Roberson
Walter Roberson 2011년 3월 30일
Probably the easiest thing would be to use
T = regexp(HoldingLine,' ','split');
T{3}

추가 답변 (1개)

Ryan
Ryan 2011년 3월 30일
Ahhh, I just figured it out, haha.
HoldingLine(6:16)
ans =
984182400

댓글 수: 2

That should be HoldingLine(7:15)
Or to be more specific, to extract the K'th word,
tP = [0, Position, length(HoldingLine)+1];
T = HoldingLine(tP(K+1)+1:tP(K+2)-1);

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Low-Level File I/O에 대해 자세히 알아보기

질문:

2011년 3월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by