필터 지우기
필터 지우기

Time conversion in a table

조회 수: 1 (최근 30일)
012786534
012786534 2016년 9월 1일
댓글: 012786534 2016년 9월 2일
Hi all, Let's say I have a table and one of my variable is a mix of numbers and NaNs, like so: [1010, NaN, 1256, NaN, 1345...]. Now, I want to convert the numbers into hours-minute format (HH:MM) and keep the same number of rows so the output looks like this : [10:10, NaN, 12:56, NaN, 13:45 ...]. Any ideas? Thanks again, you guys are great!

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2016년 9월 1일
a=[1010, NaN, 1256, NaN, 1345]
idx=isnan(a)
a(idx)=0
out=arrayfun(@(x) datestr(datenum(sprintf('%04d',x),'HHMM') ,'HH:MM') ,a,'un',0)
out(idx)={nan}
  댓글 수: 1
012786534
012786534 2016년 9월 2일
Huh. Pretty neat, Mr. Abdelmalek

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by