I've seen something to the likes of w=[w z] where z is a column vector and w is an array with both having equal number of rows
Amend a column vector to a matrix array
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
What are some simple ways to amend a column vector to an array? I am trying to avoid setting a fixed number of column vectors to an array and would rather amend column vector after column vector with a while loop until it reaches the end of the loop. Feel it would be unnecessary to fix the length of the array if this could happen and it would be more fluid
4 commentaires
Voss
le 8 Déc 2021
That will work. This also works:
w(:,end+1) = z;
It is a good idea to pre-allocate if possible, however, like Matt J points out in his answer.
Réponses (1)
Matt J
le 8 Déc 2021
Modifié(e) : Matt J
le 8 Déc 2021
it would be unnecessary to fix the length of the array if this could happen and it would be more fluid
No, it won't be more fluid, because of
A compromise would be to hold the columns in a cell array and then combine them at the end, e.g.,
i=1;
c={};
while i<10
c{i}=rand(4,1);
i=i+1;
end
A=cell2mat(c)
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!