How to preserve the percent character '%' when importing data from excel ?
5 views (last 30 days)
Show older comments
Hi, I am trying to import an excel data using xlsread. But it seems matlab cannot distinguish a cell '20%' from another cell '0.2', cuz both of them will be 'automatically' transformed to '0.2000' during the importing. Here is my issue: Even though they are numerically the same, but the '%' has a special meaning in my context which i intend to identify. Thus, is there a way to preserve the percent character '%' during the importing process?
(Presumably, i can replace '20%' with '20% bla' by search/replace '%' with '% bla' in excel, and do the importing to matlab next. But...it does not look very promising, cuz i have hundreds of excel files)
thanks a lot in advance for your help!
0 Comments
Accepted Answer
Image Analyst
on 12 Oct 2013
You're going to have to use ActiveX to query Excel and ask it the format of the cell. If the cell is general or some other format, leave it alone and it will come in as 0.2. If the format is Percent, then you can either (1) use ActiveX to convert it to a text string using copy/pase (I think) and then change the format to text, or (2) bring it into MATLAB as a number 0.2 but then convert it to a string using sprintf(). I think (2) wold be the easier route. I don't know the exact ActiveX commands to query the format of the cell - you can look it up as easy as I can.
6 Comments
Image Analyst
on 15 Oct 2013
Yeah, I've noticed that too. It seems like if you have something and then deleted it, it doesn't always seem to know where the end of the data is. Like if your last cell is Z100 and then you delete it so that your new lower right cell is M50, it still thinks the last cell is Z100 - row 100 instead of row 50. Maybe there's a property other than usedrange that is more accurate - I don't know.
More Answers (0)
See Also
Categories
Find more on ActiveX 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!