concatenation in a loop

19 vues (au cours des 30 derniers jours)
Aniket Kumar
Aniket Kumar le 8 Juin 2019
Can we concatenate two matrices in a loop? (size of one matrix will increase after every iteration)
for me its showing this error
"Error using cat
Dimensions of matrices being concatenated are not consistent."
  1 commentaire
madhan ravi
madhan ravi le 8 Juin 2019
Show the code.

Connectez-vous pour commenter.

Réponse acceptée

Prasanth Sikakollu
Prasanth Sikakollu le 8 Juin 2019
For row wise concatenation:
Here, matrix 'c' is being concatenated to matrix 'a' row wise, number of columns being constant in this case.
a = [];
c = [1 2;3 4];
for i = 1:5
c = [1*i 2*i;3*i 4*i];
a = [a;c]; % For row wise concatenation
end
For column wise concatenation:
Here matrix 'c' is being concatenated to matrix 'a' column wise, number of rows being constant in this case.
a = [];
c = [1 2;3 4];
for i = 1:5
c = [1*i 2*i;3*i 4*i];
a = [a c]; % For column wise concatenation
end
Hope this helps

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices 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!

Translated by