MATLAB: Matrix storage and extraction inside a cell or a strucutre array.

cell arraycell arraysfor loopmatrix storagestructure array

How do I store matrix and extract matrix from a cell or a structure by using a for loop??????
a=[1 2 3;4 5 6;7 8 9]
b=[11 12 13;14 15 16;7 8 19]
c=[121 212 213;14 15 16;27 28 29]
I created an cell array by following method
d=[{a},{b},{c}]
Suppose I have to retrive b from d. How do I retrive it????
Suppose a,b,c are images represented in matrix form. I need to know if these matrix can be stored in a structure or in a cell array by using a for loop and later retrived by a for loop.

Best Answer

You can use curly bracket indexing with cell arrays. To extract the content of the second element from cell array 'd', run
b = d{2};
Also, note that you should never create a related variable with different names. So instead of creating a, b, c, and then using for loop to create cell array or struct. It is better to create the cell array to being with. There are ways to create cell array using for-loop using eval(), but it is highly unrecommended in MATLAB. See the reason here: https://www.mathworks.com/matlabcentral/answers/304528-tutorial-why-variables-should-not-be-named-dynamically-eval