How to remove empty spaces in between text in a cell array?

조회 수: 3 (최근 30일)
Karthick Jonagadla
Karthick Jonagadla 2016년 2월 22일
댓글: Stephen23 2016년 2월 22일
I wish to remove the empty spaces in between text in a cell array. Any help would be appreciated . Actual:
Data={'Symbol','Date','Expiry','Open','High','Low','Close','LTP','Settle Price','No. of contracts','Turnover in Lacs','Open Int','Change in OI','Underlying Value '};
Desired:
Data={'Symbol','Date','Expiry','Open','High','Low','Close','LTP','SettlePrice','No.ofcontracts','TurnoverinLacs','OpenInt','ChangeinOI','UnderlyingValue'};

채택된 답변

Stephen23
Stephen23 2016년 2월 22일
편집: Stephen23 2016년 2월 22일
Just use strrep:
>> Data={'Symbol','Date','Expiry','Open','High','Low','Close','LTP','Settle Price','No. of contracts','Turnover in Lacs', 'Open Int','Change in OI','Underlying Value '};
>> strrep(Data,' ','')
ans =
'Symbol' 'Date' 'Expiry' 'Open' 'High' 'Low' 'Close' 'LTP' 'SettlePrice' 'No.ofcontracts' 'TurnoverinLacs' 'OpenInt' 'ChangeinOI' 'UnderlyingValue'
If you are planning on using these as fieldnames, then you might like to consider using genvarname instead:
>> genvarname(Data)
ans =
'Symbol' 'Date' 'Expiry' 'Open' 'High' 'Low' 'Close' 'LTP' 'SettlePrice' 'No0x2EOfContracts' 'TurnoverInLacs' 'OpenInt' 'ChangeInOI' 'UnderlyingValue'
  댓글 수: 2
Karthick Jonagadla
Karthick Jonagadla 2016년 2월 22일
Solution works. Thanks!
Stephen23
Stephen23 2016년 2월 22일
My pleasure! On this forum it is considered polite to accept the answer that best resolves your question.

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

추가 답변 (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