MATLAB: How to preserve the percent character ‘%’ when importing data from excel

%activexexcelimportpercent

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!

Best Answer

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.