how to create and use dynamic variable for a 2d matrix
Mostrar comentarios más antiguos
hello,
/*I got a variable */
share1 = zeros((2*s(1)), (2 * s(2))); share2 = zeros((2*s(1)), (2 * s(2)));
i want to have variable share3,share4 ....share N depending on N value
instead of typing and assigning this N times, i want to dynamically create using for loop (many threads have been written that this is a bad practice) is there any efficient way to do it and yes, i want to call the variable later
for better understanding of the question, i posted the source code link https://github.com/hopuihang/VC/tree/master/visual_cryptograpthy_ahti/Visual_Cryptography
Respuestas (1)
KSSV
el 28 de Oct. de 2016
You can make share a 3D matrix, if all the matrices have same dimensions.
share = rand(10,10,5) ;
You can access them by share(:,:,1), share(:,:,2) etc.
If the matrices are of different size, you can store them in cell.
share = cell(3,1) ;
share{1} = rand(10,5) ;
share{2} = rand(5,7) ;
share{3} = rand(5,1) ;
You can access share by share{1}, share{2}, share{3}.
As suggested by others don't try to name variables dynamically.
Categorías
Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!