Define a new binary operator in MATLAB?
显示 更早的评论
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).
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Number Theory 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!