필터 지우기
필터 지우기

Problem in reading binary data from excel file

조회 수: 11 (최근 30일)
Sajid Khan
Sajid Khan 2015년 7월 4일
답변: Image Analyst 2015년 7월 4일
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
Image Analyst 2015년 7월 4일
Unfortunately you forgot to attach abs.xlsx so probably no one is going to check out anything for you.
Sajid Khan
Sajid Khan 2015년 7월 4일
I don't need to attach abc.xlsx file I guess. Because the only thing that is in that file is binary value 1000111111001010000000
By the way here is attached file.

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

답변 (3개)

Azzi Abdelmalek
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.
  댓글 수: 2
Sajid Khan
Sajid Khan 2015년 7월 4일
I have already changed format of my cell from "General" to "Number" in excel file. The value that is in my excel file is 1000111111001010000000 . Is there anyway I can read them as they are. I mean whenever I try to read binary values in excel file using command
num = xlsread('abs.xlsx')
it makes num as a double data type variable and it's in exponential form. I have to change them into non-exponential form by using statement
num_Bin = sprintf('%23.0f',num);
it works for most of the binary values but not on the given binary value of 1000111111001010000000.
Azzi Abdelmalek
Azzi Abdelmalek 2015년 7월 4일
I said to text not number

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


Image Analyst
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};

Image Analyst
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.

카테고리

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