Cell to matrix under new variable

2 visualizaciones (últimos 30 días)
Rahul Marwaha
Rahul Marwaha el 8 de Feb. de 2021
Comentada: Rahul Marwaha el 11 de Feb. de 2021
Hi, I was wanting to convert individual cells to a matrix. For example;
A = 1x? cell % Each cell icontains just numerical values of size 3x3
B1 = [A{1,1}];
B2 = [A{1,2}];
etc .....
B? = [A(1,?)];
I essentially need the A cell's to each be converted to a matrix, however, that is for A = 1 by any number of cells. E.g. A = 1 x 6 cell or A= 1 x 12 cell etc. Just wondering how to store each cell as a matrix under a new variable each time e.g. B1, B2, ... B?. Thanks!

Respuestas (1)

James Tursa
James Tursa el 8 de Feb. de 2021
Do not do this! You are taking a method of storing your data that is easy to maintain and access (e.g., in a loop) and proposing using named variables that will be hard to maintain and access downstream in your code. See this link:
Keep your variables in the cell array, or if they are all the same size consider concatenating them into a single 3D array. Your downstream coding will be much easier!
  1 comentario
Rahul Marwaha
Rahul Marwaha el 11 de Feb. de 2021
Hi, thanks for replying! I appreciate your suggesiton and see why the maintenance of variables will be much easier. However, I'm trying to extract the data to calculate new variables e.g.
C = B1 * D * E;
% where
% B1 is the extracted 3x3 matrix
% D is another 3 x 3 matrix
% E is a 1 x 1 matrix
I was trying to use a for loop to achieve this by extracting the B matrices for a given range e.g.
x = (1,2,3,4)
B1 = [A{1,x}];
% and then
C = B1 * D * E;
The desire is to thus have a new matrix C which would be a 3 x 4 with each column being the four different 1 x 4 matrices.
Any advice or help is much appreicated, thanks!

Iniciar sesión para comentar.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by