Cell to matrix under new variable

4 ビュー (過去 30 日間)
Rahul Marwaha
Rahul Marwaha 2021 年 2 月 8 日
コメント済み: Rahul Marwaha 2021 年 2 月 11 日
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!

回答 (1 件)

James Tursa
James Tursa 2021 年 2 月 8 日
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 件のコメント
Rahul Marwaha
Rahul Marwaha 2021 年 2 月 11 日
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!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by