I need create a function for order pairs
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi I nedd create a function for do something like this (using for loops)
A = [1,2,3];
B = [4,5,6];
LA = length(A);
LB = length(B);
LT = LA*LB;
% The matrix of pair orders always be (n,2), in this case C(LT,2) = C(9,2)
C = zeros(LT,2);
C = [(1,4) ; (1,5) ; (1,6) ; (2,4) ; (2,5) ; (2,6) ; (3,4) ; (3,5) ; (3,6)];
I try using this kind of code:
C = []:
for i =1:LT
C(i) = B(A);
% or
C(i) = B[];
end
Any idea?
0 commentaires
Réponses (1)
Rik
le 10 Fév 2022
You can create indices with meshgrid or ndgrid, no loop needed.
[indA,indB]=ndgrid(1:numel(A),1:numel(B));
C=[A(indA(:)).' ; B(indB(:)).'];
0 commentaires
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!