Matlab, matrix dimensions must agree -


i need create matrix have points in 0-1 range simulating xor gate in picture bu points should exist in upper left , bottom right corners too.

enter image description here

i using code:

    pats = [0.4*rand(n/4,2);             0.4*rand(n/4,2)+0.6;             0.4*rand(n/4,2)+[0 0.5];             0.4*rand(n/4,2)-[0 0.5]+0.6]; 

and following error:

warning: size vector should row vector integer elements.  > in main @ 24  warning: size vector should row vector integer elements.  > in main @ 24  warning: size vector should row vector integer elements.  > in main @ 24  warning: size vector should row vector integer elements.  > in main @ 24  error using  +  matrix dimensions must agree.  error in main (line 24)         pats = [0.4*rand(n/4,2); 

the element wise addition doesn't work randn(n/4,2) + [0 0.5] because trying add n/4 2 matrix 1 2 matrix. need use bsxfun:

pats = [0.4*rand(n/4,2);     0.4*rand(n/4,2)+0.6;     bsxfun(@plus,0.4*rand(n/4,2),[0 0.5]);     bsxfun(@minus,0.4*rand(n/4,2),[0 0.5]) + 0.6]; 

the function bsxfun(@plus, a, b) add i-th element of b i-th column of matrix a.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -