Picking out a specific string within a string variable.
1 回表示 (過去 30 日間)
古いコメントを表示
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.
0 件のコメント
採用された回答
Walter Roberson
2011 年 3 月 30 日
Probably the easiest thing would be to use
T = regexp(HoldingLine,' ','split');
T{3}
0 件のコメント
その他の回答 (1 件)
Ryan
2011 年 3 月 30 日
2 件のコメント
Walter Roberson
2011 年 3 月 30 日
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);
参考
カテゴリ
Help Center および File Exchange で Low-Level File I/O についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!