xlsread converting TRUE to 1
古いコメントを表示
Does anyone have a work around for when xlsread reads in the raw data and converts the string TRUE into a 1???
It appears that it is doing automatic conversion to boolean, when I need to keep it as a string/char value. This doesn't happen when there are other characters in the field. I'm storing the data into cell arrays, but cannot seem to preserve a string of TRUE from an Excel spreadsheet.
Thanks,
-Mike
3 件のコメント
Oleg Komarov
2012 年 3 月 12 日
Why would you want to preserve 'true' as a string? I think it's more convenient to have it in boolean format. Can you give a counterexample?
Mike Bystedt
2012 年 3 月 12 日
Mike Bystedt
2012 年 3 月 12 日
採用された回答
その他の回答 (2 件)
owr
2012 年 3 月 12 日
0 投票
Interesting - I never ran into this before but just reproduced it myself. I dont think the issue is with MATLAB, but with Excel. If the cells are formatted (in Excel) as "text" rather than "general", this doesnt seem to happen.
7 件のコメント
Mike Bystedt
2012 年 3 月 12 日
owr
2012 年 3 月 13 日
Sorry, was hoping I would have more tiem yesterday to elaborate further - never happened. I had the same "sticky" format issue, just changing the format of the pre-populated cells to text and/or copying pasting data into ranges of cells set to format "text" didnt work for me either. Try taking a brand new spreadsheet, format a range as text, and then write in a few test "true" and "false" and read these into MATLAB. You can tell if the logical XL format kicks in if it converts your a lowercase "true" into "TRUE". This is what convinced me that the issue is an automatic formatting issue with XL. As far as the real problem of converting your already existing data into a non XL-logical format, I havent figured that out yet. Id try cutting and pasting your data into a "text" formatted range in XL with "use destimation format" or someting similar. Im not an expert in XL and always get frusturated in how it assumes I want to do something other than what Im trying to do. Good luck.
owr
2012 年 3 月 13 日
Yuo can try the "TEXT" function in Excel. If you have boolean "TRUE" in cell A1, type =TEXT(A1,"") in B1 and repeat this formula for your whole column of TRUE/FALSE. When you xlsread the B column it comes into ML correctly.
Mike Bystedt
2012 年 3 月 13 日
Oleg Komarov
2012 年 3 月 13 日
Doesn't my method work?
Mike Bystedt
2012 年 3 月 13 日
Image Analyst
2012 年 3 月 13 日
So you mean that the users pasted stuff in there, like the word TRUE, and Excel did the conversion to 1, and it got saved as a 1? So when you open it up again in Excel it should be 1 not TRUE. If so, then that's an Excel issue that happens even before MATLAB is involved in any way. Is that what you're saying?
Image Analyst
2012 年 3 月 12 日
Make up a cell array, like this:
ca = {'True','False'; 12,98; 13,99; 14,97};
xlswrite('deleteMe.xlsx', ca, 1, 'E1');
The only trick is that you have to have the same number of text cells as numerical cells. Note that the above example (adapted from the help for xlswrite) has exactly two columns. But you can have empty cells if you want, like this:
ca = {'True',''; 12,98; 13,99; 14,97};
xlswrite('deleteMe.xlsx', ca, 1, 'E1');
4 件のコメント
Mike Bystedt
2012 年 3 月 12 日
Image Analyst
2012 年 3 月 12 日
Oh, sorry - you're using xlsread - I misread and thought you were trying to use xlswrite. So, did you take all three outputs of xlsread()? Especially the "raw" cell array?
Mike Bystedt
2012 年 3 月 12 日
Image Analyst
2012 年 3 月 13 日
I'll see if I have time to make up my own spreadsheet to try it tomorrow.
カテゴリ
ヘルプ センター および File Exchange で Spreadsheets についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!