Problem in reading binary data from excel file
8 次查看(过去 30 天)
显示 更早的评论
I have an excel file that contains binary data in single cell. The binary data that is stored in excel is given below 1000111111001010000000
I am trying to read data in excel file using command
num = xlsread('abs.xlsx');
The data that is stored in num varialbe is 1.0001e+21. When i try to expands e+21 using command
num_Bin = sprintf('%23.0f',num);
it returns value of 1000111111001009900000 which is not a binary number. Can someone please tell me what's the problem with it?
2 个评论
Image Analyst
2015-7-4
Unfortunately you forgot to attach abs.xlsx so probably no one is going to check out anything for you.
回答(3 个)
Azzi Abdelmalek
2015-7-4
1.0001e+21 is not also a binary number. Before importing your xlsx file, change the format of your cells to text.
Image Analyst
2015-7-4
That is a decimal number, not a binary number. To get a binary number like you're thinking of it, you need to put a single or double quote symbol in front of it so that Excel will treat it as a string. Then you can do
[numbers, strings, raw] = xlsread('abc.xlsx');
binaryString = raw{1,1};
0 个评论
Image Analyst
2015-7-4
OK, see my expanded explanation/solution:
% If you have a ' or " in front of the string in Excel
% so Excel knows it's a string and not a decimal number, do this:
[numbers, strings, raw] = xlsread('abc.xlsx');
binaryString = raw{1,1}
% If you DO NOT have a ' or " in front of the string in Excel
% so Excel thinks 1000111111001010000000 is a decimal number
% of 1.00011111100101e+21 , do this:
[numbers, strings, raw] = xlsread('abc.xlsx');
binaryString = raw{1,1}
% IMPORTANT NOTE 1000111111001010000000 is the decimal number
% and will not still look like 1000111111001010000000 (the same)
% once it is converted into a binary string.
% Just like 101 (a hundred and 1) looks like
% 1100101 when converted into binary, not 101
% which you'd get if the number were 5, not 101.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!