I need create a function for order pairs
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Rik
am 10 Feb. 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 Kommentare
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!