# Matrix Help

Hello,

I am new to Matlab and need some help with my matrix. I am currently making a random 4x6 matrix of zeros and ones. Taking each row, and turning it into a decimal number. Then using my fourbfiveb function, finding the row equal to that decimal number and outputting the binary number in the row. My problem is that each time the for loop runs, it overwrites the previous value of v.

I'd like the output to be put into a new 5x6 matrix, but cannot figure out the code for it. At the very least I'd like to have each row labeled something differently.

Here is my current code:

[color=Blue]clear;
A=randint(6,4,2);

for n=1:4

B=A(n,:);
c = num2str(B);
h=bin2dec(c);

v= fourbfiveb(h)

end;[/color]

And the fourbfiveb function is:

[color=Blue]function v=fourbfiveb(hexin)
% v=fourbfiveb(h)
%
% returns a 5 bit encoding for the hex digit "h" (h=0 to 15).
%
table4b5b=[ 1 1 1 1 0;
0 1 0 0 1;
1 0 1 0 0;
1 0 1 0 1;
0 1 0 1 0;
0 1 0 1 1;
0 1 1 1 0;
0 1 1 1 1;
1 0 0 1 0;
1 0 0 1 1;
1 0 1 1 0;
1 0 1 1 1;
1 1 0 1 0;
1 1 0 1 1;
1 1 1 0 0;
1 1 1 0 1];
v=table4b5b(hexin+1,:);[/color]

Your help is very much appreciated. Thanks!

-Anthony

• before the loop try

[code]v = zeros([4 1])[/code]

[code]v(n)= fourbfiveb(h)[/code]

• I tried that, but getting an error:

[color=Blue]??? In an assignment A(I) = B, the number of elements in B and
I must be the same.
[/color]

Not really sure what that means, or how to correct it. Thanks.