Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
Binary format reading into matlab
조회 수: 2 (최근 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!