#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

#### Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmers Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use it's exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

# Matrix Help

Posts: 2Member
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
· ·

• Posts: 2Member
before the loop try

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

then for your 'v'
[code]v(n)= fourbfiveb(h)[/code]

· ·
• Posts: 2Member
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.
· ·