Dealing with string values
3 views (last 30 days)
Show older comments
Hi, all. I am dealing with a large amount of data with three columns, id, x, y.
While the ids are numeric, they need to be treated as text, for example some are 094567 and I cannot have MatLab stripping the leading 0 and making it 94567, which seems to happen with importdata(_____,'\t')
Is there a command that will treat these more appropriately?
Thanks,
-Clay
0 Comments
Accepted Answer
Image Analyst
on 26 Jul 2014
Here's one way:
clc;
numRows = 10;
m = randi(999999, numRows, 1) % Sample data
charm = sprintf('%6.6d', m) % Convert to 1-D character array.
charm = reshape(charm, [6, numRows]) % Back to 2D
charm = charm'
4 Comments
Image Analyst
on 26 Jul 2014
Then it will have to be strings. I don't know of any way, like your buddy apparently does, to deal with leading zeros if they're pure numbers stored in a computer like in the usual IEEE format.
More Answers (1)
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!