-2

I have this code for CRC code in MATLAB, msg is the data and poly is the generator function.

msg=[1 0 1 1 0 0 1 0 1 ]; 
poly=[1 0 1 1]; 
[M, N]=size(poly);
mseg=[msg zeros(1,N-1)];
[q, r]=deconv(mseg,poly);
r=abs(r); 
for i=1:length(r)
        a=r(i);
        if ( mod(a,2)== 0 )
            r(i)=0;
        else
            r(i)=1;
        end end

    crc=r(length(msg)+1:end) frame = bitor(mseg,r)

It works well but I want to do it for random msg with size of 7. I used this but it has error.

msg = randi([0, 1], 7,1);

The error is:

Error using horzcat Dimensions of matrices being concatenated are not consistent.

please help me with this problem.

user3637733
  • 91
  • 1
  • 8
  • 1
    what is the error ? – farbiondriven Apr 13 '18 at 14:25
  • 1
    You have a lot of previous questions that have very good answers. Consider revisiting them and marking the best answer that solves your problem as [accepted](http://meta.stackexchange.com/a/5235/) by clicking **`✔`**, on the left side of the answers (one answer per post can be marked as accepted). You can also [upvote](http://meta.stackexchange.com/a/173400/) all the helpful answers by clicking **`▲`**, on the left side of the answers. This is the least that you can do for the people who are volunteering their time for your problems – Sardar Usama Apr 13 '18 at 14:32

1 Answers1

2

Have you tried: msg = randi([0, 1], 1, 7); ?

Notice the switching of the 7, 1 to 1, 7. Please see if this solves your problem.

Alex Zavatone
  • 4,106
  • 36
  • 54
farbiondriven
  • 2,450
  • 2
  • 15
  • 31