Info
この質問は閉じられています。 編集または回答するには再度開いてください。
Binary format reading into matlab
3 ビュー (過去 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!