I need to separate 3 conjoined values into 3 separate values

I have a column of conjoined values (27.525.525.0) which I need to split into separate values (27.5, 25.5, 25.0) so they can be graphed. Thank you for any help!

3 件のコメント

James Tursa
James Tursa 2017 年 3 月 8 日
It doesn't look like a column. Is this a string that you need parsed into numbers?
Adam
Adam 2017 年 3 月 8 日
There also isn't a unique way to separate that conjoined 'thing' into 3 values unless there are rules to go with it e.g.
27.52, 5.52, 5.0
would equally be a separation into 3 values.
Greig
Greig 2017 年 3 月 8 日
It's three separate temperature readings. Over 16 million lines worth... But the program wasn't set up to create the string as three csv values and I don't know how to break the column into three columns, each composed of a xx.x numnber

サインインしてコメントする。

回答 (1 件)

Star Strider
Star Strider 2017 年 3 月 9 日
編集済み: Star Strider 2017 年 3 月 9 日

0 投票

If you read them in as strings, you can parse them into individual strings with the appropriate numbers with a simple regexp call. Then convert them to a numeric array:
T = '27.525.525.0'; % String Input
NrCell = regexp(T, '\d{2}\.\d', 'match') % Parse
NrVctr = cellfun(@str2double, NrCell) % Convert To Numeric Vector
NrCell =
1×3 cell array
'27.5' '25.5' '25.0'
NrVctr =
27.5 25.5 25
We do finally end up with a numeric (1x3) row vector.
This will require a loop to send each string to regexp (it cannot read a column matrix of strings), then store ‘NrVctr’ as a row in a matrix.
EDIT Made ‘NrVctr’ more efficient, corrected ambiguities in description.

カテゴリ

タグ

質問済み:

2017 年 3 月 8 日

編集済み:

2017 年 3 月 9 日

Community Treasure Hunt

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

Start Hunting!

Translated by