Picking out a specific string within a string variable.

1 Ansicht (letzte 30 Tage)
Ryan
Ryan am 30 Mär. 2011
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.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 30 Mär. 2011
Probably the easiest thing would be to use
T = regexp(HoldingLine,' ','split');
T{3}

Weitere Antworten (1)

Ryan
Ryan am 30 Mär. 2011
Ahhh, I just figured it out, haha.
HoldingLine(6:16)
ans =
984182400
  2 Kommentare
Walter Roberson
Walter Roberson am 30 Mär. 2011
That should be HoldingLine(7:15)
Walter Roberson
Walter Roberson am 30 Mär. 2011
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);

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Low-Level File I/O finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by