unexpected use of 00:00:01 in a scalar context matlab

조회 수: 5 (최근 30일)
Andrea Sbaragli
Andrea Sbaragli 2021년 5월 24일
댓글: Andrea Sbaragli 2021년 5월 24일
if abs(Int12{i,6}- F1{j,1}) <= '00:00:01' why is it not corret?
  댓글 수: 1
Daniel Pollard
Daniel Pollard 2021년 5월 24일
Can you give some more context? Since we don't know what Int12 or F1 are, it's not easy to help. What are you trying to do?

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

채택된 답변

Walter Roberson
Walter Roberson 2021년 5월 24일
In MATLAB '00:00:01' is a character vector. When you use a character vector in a numeric expression, most of the time the character vector will have each character converted to the Unicode position number used to encode the character.
double('00:00:01')
ans = 1×8
48 48 58 48 48 58 48 49
You would then be comparing whatever is on the left side of the < to that vector of numbers, getting out a vector of logical results.
If the values you are working with just happen to be datetime objects then subtracting would give a duration object. You can then compare
if abs(Int12{i,6}- F1{j,1}) <= duration('00:00:01')
or more compactly
if abs(Int12{i,6}- F1{j,1}) <= seconds(1)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by