Dealing with string values

3 views (last 30 days)
Clayton
Clayton on 26 Jul 2014
Answered: Clayton on 26 Jul 2014
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

Accepted Answer

Image Analyst
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
Clayton
Clayton on 26 Jul 2014
Thanks for the heads up, Image Analyst.
You are right that I don't need the leading zero. My code works just fine for the analytical part. It is just that I am giving these analyses to a buddy. He needs that leading zero to be copacetic with his database, so I am trying to accommodate his needs.
Image Analyst
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.

Sign in to comment.

More Answers (1)

Clayton
Clayton on 26 Jul 2014
Thanks, all, for the input. It looks like I'll have to input in, analyze the data as is, and then monkey with the format upon export to fit my friends database needs.
Again. Thanks for taking the time to respond.

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!