필터 지우기
필터 지우기

Selecting Numbers from a String in a Matrix

조회 수: 1 (최근 30일)
Katy Weihrich
Katy Weihrich 2018년 2월 26일
댓글: Katy Weihrich 2018년 2월 28일
I used the
B = regexp(A,'\d*','Match');
comment to identify the year, month, day, hour, min, sec and msec of a weird Timestamp (written as: 2018-02-13T14:07:14.000Z).
It worked well when I used
Timestamp = regexp('2018-02-13T14:07:14.000Z','\d*','Match')
But as soon as I tried to apply it to a matrix by using
Date = Matrix_Text(:,2)
Timestamp = regexp(Date,'\d*','Match')
I only got {1×7 cell} as the answer of each cell.
When I tried to identify the problem by only including one value at first:
Date = Matrix_Text(2,2)
Timestamp = regexp(Date,'\d*','Match')
The output was {1×7 cell} again.
Does someone know what the error could be?
  댓글 수: 1
Jan
Jan 2018년 2월 26일
Why do you assume, that there is an error? If Matrix_Text is a cell array, this is the expected behavior. This would be immediately clear, if you post, what this array is. Of course we cannot guess this.

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

채택된 답변

Stephen23
Stephen23 2018년 2월 26일
편집: Stephen23 2018년 2월 26일
"The output was {1×7 cell} again."
"Does someone know what the error could be?"
There is no error, because that is the expected behavior. The regexp help states that "If either str or expression is a cell array of character vectors or a string array, and the other is a character vector or a string scalar, the output is a cell array of row vectors. The output cell array has the same dimensions as the input array".
So when you provide the input as a cell array of strings/char vectors, then the output is a cell array containing the outputs that you would expect if the input was just one char vector. It is basically equivalent to doing this:
out{1} = regexp(inp{1},...)
out{2} = regexp(inp{2},...)
out{3} = regexp(inp{3},...)
...
so if you want to access the output data then you will need to dig one cell deeper using cell array indexing:
out{1}
out{2}
...
Tip: vertcat probably gives you what you want:
out = regexp(Matrix_Text(:,2),...);
out = vertcat(out{:});
  댓글 수: 1
Katy Weihrich
Katy Weihrich 2018년 2월 28일
Thank you very much! That really helped! Especially the vertcat tip!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by