Define a new binary operator in MATLAB?
Show older comments
Hi,
I wondered whether it is possible to define a new, binary operator in MATLAB. The thing is, I need a new operator to "multiply" two matrices in an uncommon way, like this:
A = [.5 .5 0; 0 1 0; 0 .5 .5];
B = [.5 .5 0; 0 1 0; 0 .5 .5];
RowsA = size(A,1);
ColsA = size(A,2);
RowsB = size(B,1);
ColsB = size(B,2);
C = zeros(RowsA*RowsB, ColsA*ColsB);
for i = 1:RowsA
for j = 1:ColsA
C( 1+(i-1)*RowsB:i*RowsB, 1+(j-1)*ColsB:j*ColsB ) = A(i,j) * B;
end
end
Instead of making a function and calling C = myfunction(A,B), I'd like to use C = A # B, with # the new operator (or perhaps another symbol if this is not possible).
Accepted Answer
More Answers (0)
Categories
Find more on Number Theory in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!