How to use CROSS with 3x1 Matrix on a 3xN Matrix
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Marcus W
am 14 Dez. 2018
Kommentiert: Marcus W
am 16 Dez. 2018
Hello,
I have 3x1 Matrix and want to do the CROSS of each element of a 3xN Matrix, to receive a 3xN Matrix as results.
Can I do this without a loop?
Thanks in advance!
0 Kommentare
Akzeptierte Antwort
James Tursa
am 14 Dez. 2018
Bearbeitet: James Tursa
am 14 Dez. 2018
Unfortunately, the cross( ) function does not auto-expand the dimensions of the operands. So you would have to manually do this or use a loop. E.g., if your vector is v and your matrix is M, then
result = cross(repmat(v,1,size(M,2)),M);
Weitere Antworten (1)
Bruno Luong
am 14 Dez. 2018
For my own use I have written this function
%%
function c = cross_dim1(a,b)
% Calculate cross product along the first dimension
c = zeros(size(a));
c(3,:) = a(1,:).*b(2,:)-a(2,:).*b(1,:);
c(1,:) = a(2,:).*b(3,:)-a(3,:).*b(2,:);
c(2,:) = a(3,:).*b(1,:)-a(1,:).*b(3,:);
end
If you have R2016b or ulterior it will do auto expansion.
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!