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 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Vishal Chaudhary
el 7 de En. de 2019
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 comentarios
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!