Cell to matrix under new variable

4 Ansichten (letzte 30 Tage)
Rahul Marwaha
Rahul Marwaha am 8 Feb. 2021
Kommentiert: Rahul Marwaha am 11 Feb. 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!

Antworten (1)

James Tursa
James Tursa am 8 Feb. 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 Kommentar
Rahul Marwaha
Rahul Marwaha am 11 Feb. 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!

Melden Sie sich an, um zu kommentieren.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by