Hi for all...
i have error when using horzcat >>> i crate two vectors randomly ( count1=randi(0:1 ,[1,32]); ) and ( count2=randi(0:1 ,[1,32]); ) and i have this vector number ( d0 = dec2bin( 17623,15); ) the problem is : when i using horzcat ( count1,count2,d0) the result appear with some symbols
can anyone help me

 채택된 답변

Star Strider
Star Strider 2015년 1월 25일

0 개 추천

The problem is that the output from dec2bin is a string, so horizcat considers everything a string. The ‘symbols’ you see are therefore ‘d0’. To see all of the variables as a string of [0 1] ‘bits’ (strings in this instance), use num2str:
count1=num2str(randi(0:1 ,[1,32]),'%d');
count2=num2str(randi(0:1 ,[1,32]),'%d');
d0 = dec2bin( 17623,15);
result = horzcat(count1,count2,d0)

댓글 수: 4

mays afif
mays afif 2015년 1월 25일
편집: Star Strider 2015년 1월 25일
thank you .. but i cann't using (xor)operation with the result
count1=num2str(randi(0:1 ,[1,32]),'%d');
count2=num2str(randi(0:1 ,[1,32]),'%d');
d0 = dec2bin( 17623,15);
result1 = horzcat(count1,count2,d0)
count4=num2str(randi(0:1 ,[1,32]),'%d');
count3=num2str(randi(0:1 ,[1,32]),'%d');
d0 = dec2bin( 17623,15);
result2 = horzcat(count3,count4,d0)
did you have another suggestion
Star Strider
Star Strider 2015년 1월 25일
편집: Star Strider 2015년 1월 25일
My pleasure.
You didn’t mention using xor!
It’s necessary to be creative for this to work:
count1=num2str(randi(0:1 ,[1,32]),'%d');
count2=num2str(randi(0:1 ,[1,32]),'%d');
d0 = dec2bin( 17623,15);
result1 = horzcat(count1,count2,d0);
count4=num2str(randi(0:1 ,[1,32]),'%d');
count3=num2str(randi(0:1 ,[1,32]),'%d');
d0 = dec2bin( 17623,15);
result2 = horzcat(count3,count4,d0);
result1n = uint8(result1)-48;
result2n = uint8(result2)-48;
xor_result = xor(result1n, result2n);
fprintf(1, ['\nxor_result = ' repmat('% d', 1, length(xor_result)) '\n'], xor_result);
produces (in this instance, results will differ between runs):
xor_result = 1 0 1 0 0 1 1 1 0 1 1 1 0 1 1 0 0 1 1 1 1 0 0 1 1 1 0 0 0 1 0 0 1 0 1 1 1 1 1 1 0 0 0 0 0 0 0 1 0 1 1 0 0 0 1 0 0 0 0 1 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
There might be more efficient ways to do this (since I don’t usually work with binary strings). Even if inefficient, this has the virtue of producing the correct result.
mays afif
mays afif 2015년 1월 25일
thank you very much
Star Strider
Star Strider 2015년 1월 25일
My pleasure!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Dates and Time에 대해 자세히 알아보기

태그

질문:

2015년 1월 25일

댓글:

2015년 1월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by