matlab - Matrix division with defined Array -
matlab - Matrix division with defined Array -
i trying split each element of matrix "a" each element of "b". want create new matrix of 4 "c"
a=[5 6 9 1; 3 8 9 5; 5 4 2 0;7 8 2 1] b=[-0.1125,-0.0847,-0.0569,-0.0292] c = ./ b
but getting error of
in assignment a(i) = b, number of elements in b , must same.
how prepare issue?
try this
c = a./repmat(b,size(a,1),1);
use @shai's reply faster. here stats
n = 100; k = 100; = randi(1000,n,n); b = randi(1000,1,n); #mine method tic; = 1:k c = a./repmat(b,size(a,1),1); end mine = toc mine = 1.2330 seconds #shai's method tic; =1:k c = bsxfun(@rdivide, a, b ); end shai = toc shai = 0.1085 seconds
i can give more general reply if give me general dimensions
matlab
Comments
Post a Comment