How can I concatenate 163 matrices into a single matrix with a loop?

1 vue (au cours des 30 derniers jours)
Gökhan Bilgin
Gökhan Bilgin le 27 Nov 2020
Commenté : Ameer Hamza le 27 Nov 2020
I have 163 arrays with same sizes, how can i combine these matrices into a single matrix like M(:,:,163).
I can't organize the loop to do;
M(:,:,1)=G1
M(:,:,2)=G2
....
M(:,:,163)=G163
Thanks very much.

Réponse acceptée

Ameer Hamza
Ameer Hamza le 27 Nov 2020
Modifié(e) : Ameer Hamza le 27 Nov 2020
The first problem here is to name your variable like G1, G2, ..., G163. It is known to be a bad coding practice: https://www.mathworks.com/matlabcentral/answers/304528-tutorial-why-variables-should-not-be-named-dynamically-eval and this question show why. Although the use of "eval" is usually discouraged, however, you can use it once to store your data in an array
G = eval(['{' strjoin(compose('G%d', 1:163), ',') '}']);
G = cat(3, G{:});
  2 commentaires
Gökhan Bilgin
Gökhan Bilgin le 27 Nov 2020
I'm new to coding, so thank you very much for your guidance and your help. And i will consider this tutorial in my future work.
Ameer Hamza
Ameer Hamza le 27 Nov 2020
I am glad to be of help!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Multidimensional 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!

Translated by