필터 지우기
필터 지우기

How to preserve the percent character '%' when importing data from excel ?

조회 수: 6 (최근 30일)
Anthony
Anthony 2013년 10월 12일
댓글: Image Analyst 2013년 10월 15일
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!

채택된 답변

Image Analyst
Image Analyst 2013년 10월 12일
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
Anthony
Anthony 2013년 10월 15일
편집: Anthony 2013년 10월 15일
thanks for pointing out. updated, although those 'sheet.usedrange.rows.count' is not quite reliable. indeed, faster (not fast enough though...) :P
Image Analyst
Image Analyst 2013년 10월 15일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by