Define a new binary operator in MATLAB?
Afficher commentaires plus anciens
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).
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Number Theory dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!