kindly can anybody suggest and help me to correct my code ?

조회 수: 1 (최근 30일)
aditya kumar sahu
aditya kumar sahu 2016년 11월 10일
답변: John D'Errico 2016년 11월 10일
s=[0 1];
Let
k{1,2}{1,1}=01010001
k{1,2}{1,2}=11010101
k{1,2}{1,3}=01010001
k{1,2}{1,4}=11010001
k{1,2}{1,5}=00010001 (continued upto {1,2}{1,7})
%
if (strcmp(k{1,2}{1,1}, '00000001') || (strcmp(k{1,2}{1,1}, '10000000')))&& s(1)==0
p{i,j}='00000001';
%
elseif (strcmp(k{1,2}{1,1}, '00000001') || (strcmp(k{1,2}{1,1}, '10000000')))&& s(1)==1
p{i,j}='10000000';
%
elseif (strcmp(k{1,2}{1,2}, '0000001') || (strcmp(k{1,2}{1,2}, '1000000')))&& s(1)==0
p{i,j}='0000001';
%
elseif (strcmp(k{1,2}{1,2}, '0000001') || (strcmp(k{1,2}{1,2}, '1000000')))&& s(1)==1
p{i,j}='1000000';
%
elseif (strcmp(k{1,2}{1,3}, '000001') || (strcmp(k{1,2}{1,3}, '100000')))&& s(1)==0
p{i,j}='000001';
%
elseif (strcmp(k{1,2}{1,3}, '000001') || (strcmp(k{1,2}{1,3}, '100000')))&& s(1)==1
p{i,j}='100000';
%
elseif (strcmp(k{1,2}{1,4}, '00001') || (strcmp(k{1,2}{1,4}, '10000')))&& s(1)==0
p{i,j}='00001';
%
elseif (strcmp(k{1,2}{1,4}, '00001') || (strcmp(k{1,2}{1,4}, '10000')))&& s(1)==1
p{i,j}='10000';
%
elseif (strcmp(k{1,2}{1,5}, '0001') || (strcmp(k{1,2}{1,5}, '1000')))&& s(1)==0
p{i,j}='0001';
%
elseif (strcmp(k{1,2}{1,5}, '0001') || (strcmp(k{1,2}{1,5}, '1000')))&& s(1)==1
p{i,j}='1000';
it is running fine as expected but what i want is suppose at the condition
>> elseif (strcmp(k{1,2}{1,5}, '0001') || (strcmp(k{1,2}{1,5}, '1000')))&& s(1)==1
is met.
i want p{i,j}= '00011000' i.e it should contain the value '1000' and its before original values also. similarly for other cases also. kindly can anybody suggest and help me.
  댓글 수: 2
Steven Lord
Steven Lord 2016년 11월 10일
Can you explain in words (NO CODE) what you're trying to do? What are the inputs to this procedure and what should the procedure output?
aditya kumar sahu
aditya kumar sahu 2016년 11월 10일
편집: Walter Roberson 2016년 11월 10일
First of all there are some binary numbers let, x=01100001,...etc. I want to compare those with some conditions like
if x==00000001 or 10000000 and y==0
then x=00000001
elseif x==00000001 or 10000000 and y==1
then x=10000000
elseif .......(continued until it matches)
so finally for x==000001 or 100000 and (s=0/1) it will match..
at this point i need the value of x should be 011000001 ..
Thats it,...i hope now you can get..

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

답변 (1개)

John D'Errico
John D'Errico 2016년 11월 10일
You may think that this produces a binary number.
k{1,2}{1,1}=01010001
It does not. It stores a double precision number: 1010001. Note there is not even a leading zero.
You cannot then do a comparison like this:
strcmp(k{1,2}{1,1}, '00000001')
And expect anything to work properly.
You need to read about data types in MATLAB. Learn the difference between strings and numeric types.

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by