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
0 个评论
回答(1 个)
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);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!