create a vector without for
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
vincent lin
le 19 Jan 2020
Commenté : Stephen23
le 19 Jan 2020
The vector structure is like [a b c d e f g h i j]
a=1:10
b=1:10
...
j=1:5
vect=[]
I can use for a =1:10
for b=1:10
...
vect = [vect;a.b...j]
end
end
but it looks not elegant. Is there a better way to generate it?
8 commentaires
Stephen23
le 19 Jan 2020
"I'd like to have possible permutation"
Then you should have asked about generating permutations: http://xyproblem.info/
Réponse acceptée
Walter Roberson
le 19 Jan 2020
a=1:10;
b=1:10;
c=1:3;
d=1:5;
[A, B, C, D] = ndgrid(uint8(a), uint8(b), uint8(c), uint8(d)) ;
v = [A(:), B(:), C(:), D(:)] ;
0 commentaires
Plus de réponses (1)
Image Analyst
le 19 Jan 2020
Try
a = 1 : 10
b = 1 : 10
...
j = 1 : 5
outputVector = [a, b, c, d, e, f, g, h, i, j]
0 commentaires
Voir également
Catégories
En savoir plus sur Matrices and Arrays 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!