Info
此问题已关闭。 请重新打开它进行编辑或回答。
Binary format reading into matlab
1 次查看(过去 30 天)
显示 更早的评论
Hello,
clear all
clc
Input_Binary=sprintf('Enter binary data \nHit Enter after completetion')
i=1;
while 1
d=input('');
if d==0 || d==1
x(i)=logical(d);
else
if d=='\n'
disp('input ended');
break;
else
disp('wrong binary input: continue input');
continue
end
end
d=0;
i=i+1;
end
Aim of the program:
I want to take 10110101010100101010 as single input. But I have to store it in variable x in logical format
>>x= 1 0 1 1 0 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0
For this I have written the above code.
Following Observations: 1. The matlab function input() is taking any length of digit. But I need only one input value either 0 or 1. How to do it?
2. When I hit enter, disp('input ended'); is not working. How to do this
3. The following error is showing when I do hit enter twice
??? Operands to the || and && operators must be convertible to logical
scalar values.
Error in ==> readbianary at 12
if d==0 || d==1
Why?
0 个评论
回答(2 个)
Walter Roberson
2011-4-7
When the user presses return without entering any data, the empty array is returned.
If you require that a single keystroke be read at a time, then you might be able to use one of the contributions to the MATLAB File Exchange.
1 个评论
Fangjun Jiang
2011-4-7
Use one input() to get a string of '01010100100', then do the following:
A='0101010101010110';
B=str2num(A(:))
0 个评论
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!