Get number after colon

조회 수: 1 (최근 30일)
Dion Theunissen
Dion Theunissen 2021년 7월 28일
댓글: Peter Perkins 2021년 7월 29일
I have a text with numbers column in a table. Now i want to only select the numbers after a colon (:)
I have no idea where to start, kan anyone help me? The table looks like this:
Now i want to check column 1 and read only the numbers behind a :
So row 1 I need 34.94, skip untill row 5, get 34.94 and so on.
  댓글 수: 3
Dion Theunissen
Dion Theunissen 2021년 7월 28일
Check out the attachment
Cris LaPierre
Cris LaPierre 2021년 7월 28일
Please share the code you use to import this data into MATLAB.

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

채택된 답변

DGM
DGM 2021년 7월 29일
편집: DGM 2021년 7월 29일
I don't know that I'd bother trying to directly operate on the table. Maybe there are tools that make that easier, but I never use tables. If the relevant column is extracted as a cell vector of chars or as a column vector of strings, then regexp() can be used:
extracted = {'blah blah blah (blah): 23.345 blah blah blah';
'blah blah blah (blah):23.34 blah 123 blah';
'blah blah blah'}
extracted = 3×1 cell array
{'blah blah blah (blah): 23.345 blah blah blah'} {'blah blah blah (blah):23.34 blah 123 blah' } {'blah blah blah' }
out = regexp(extracted,'(?<=: *)[0-9]+(\.[0-9]+)?','match');
format compact; celldisp(out) % just for web display
out{1}{1} = 23.345 out{2}{1} = 23.34 out{3} = {}
... at which point it can be inserted into the table or whatever else is required for further processing. If you want a numeric vector:
out = cellfun(@str2double,out,'uniform',false);
out(cellfun(@isempty,out)) = {0}; % replace empty elements with zero (or use NaN if you want)
out = vertcat(out{:})
out = 3×1
23.3450 23.3400 0
  댓글 수: 1
Peter Perkins
Peter Perkins 2021년 7월 29일
DGM, you are correct. This is what dot subscripting on tables is for:
x = t.X;
<lengthy multiple-line computation on x to create y>
t.Y = y;
It may be that the computations are short enough that you can just do the subscripting in-line:
t.Y = <some calculation on t.X>
And of course this all assumes that y is the same length as x.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Identification에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by