MATLAB Answers

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

1 view (last 30 days)
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;
Thanks very much.


Sign in to comment.

Accepted Answer

Ameer Hamza
Ameer Hamza on 27 Nov 2020
Edited: Ameer Hamza on 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: 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{:});


Gökhan Bilgin
Gökhan Bilgin on 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.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by