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 ビュー (過去 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 で Loops and Conditional Statements についてさらに検索
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

