필터 지우기
필터 지우기

How to replace space with zero in a table?

조회 수: 3 (최근 30일)
Sonima
Sonima 2019년 1월 22일
답변: Peter Perkins 2019년 1월 23일
Hi!
I want to replace space with zero in the H4.Time without loop.
K>> head(H4)
ans =
8×7 table
Date Time Open High Low Close Volume
________ ______ _____ _____ _____ _____ ______
20010102 200000 64.3 64.35 64.25 64.35 184
20010103 0 64.3 64.75 64.3 64.59 924
20010103 40000 64.6 64.7 64.39 64.52 932
20010103 80000 64.51 64.73 64.48 64.58 892
Any suggestion without loop to fix it?
Thanks.
  댓글 수: 1
Walter Roberson
Walter Roberson 2019년 1월 22일
Are the entries char or are they numeric? If they were originally numeric that got converted to fixed width then why not just 0 pad at the time?
Time = num2str([200000;0;40000;80000], '%06d')

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

채택된 답변

Walter Roberson
Walter Roberson 2019년 1월 22일
H4.Time(H4.Time == ' ') = '0';

추가 답변 (1개)

Peter Perkins
Peter Perkins 2019년 1월 23일
Sia, you may find that using the datetime datatype for Date, and the duration data type for Time, makes your life easier. Storing numbers as text is not likely to very convenient.

카테고리

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