필터 지우기
필터 지우기

I'm trying to create a binary to unary encoding converter. However I am getting stuck on one of the final loops. Which should print out the number of ones for the positional value. After this I plan on adding the resulting matrices together.

조회 수: 2 (최근 30일)
A=[1 0 1];
l=length(A);
un = zeros(1, l);
for N = 1:l %position is (N-1)
% B=A(N:end); ignore
un(N)=(2^(N - 1));
mul= un .* A; %find positional value
%Unary = zeros(1, mul);
for i = 2:mul %error here, needs to be a scalar value
Unary(i)= i./i; %therfore unary gets defined as '1' stuck on first iteration i think
end
end
%paper for reference to unary; https://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=8309178

답변 (1개)

Vishal Chaudhary
Vishal Chaudhary 2019년 1월 7일
In the second for loop, since, mul is array, try using mul(N) to access the elements and change the logic accordingly. I think a better way would be to convert to decimal first and then make array of 1's which will be required unary conversion. Something like below:
A=[1 0 1];
deci = bi2de(A);
unary = ones(1,deci);

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by