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.
    7 views (last 30 days)
  
       Show older comments
    
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 Comments
Answers (1)
  Vishal Chaudhary
    
 on 7 Jan 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 Comments
See Also
Categories
				Find more on Loops and Conditional Statements in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
