How to remove empty spaces in between text in a cell array?
3 views (last 30 days)
Show older comments
Karthick Jonagadla
on 22 Feb 2016
Commented: Stephen23
on 22 Feb 2016
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'};
0 Comments
Accepted Answer
Stephen23
on 22 Feb 2016
Edited: Stephen23
on 22 Feb 2016
>> 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 Comments
Stephen23
on 22 Feb 2016
My pleasure! On this forum it is considered polite to accept the answer that best resolves your question.
More Answers (0)
See Also
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!