how to fill a vector with another ones
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
hello everyone i have two vectors:
A=[ X Y Z T ]
B=[ X' Y' Z' T' ]
i wanna create a vectors
C1=[X X']
C2=[Y Y']
C3=[Z Z']
C4=[T T']
0 commentaires
Réponse acceptée
the cyclist
le 23 Déc 2015
Modifié(e) : the cyclist
le 23 Déc 2015
A = [ 1 2 3 4];
B = [ 5 6 7 8];
N = numel(A);
C = cell(N,1);
for ni = 1:N
C{ni} = [A(ni) B(ni)]
end
It is generally a poor idea to name variables C1, C2, etc. There are lots posts here about that fact.
Instead, a better solution is to use cell arrays, that can store vectors (and other object) in their elements.
Later in your code, simply refer to C{1}, which is the contents of the first element in C, in the same way you would have used C1.
2 commentaires
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!