Azzera filtri
Azzera filtri

I have a 1x50 cell array with a 780x6 table in each cell. I can access the cells but i would like to convert the different tables into matrices and give them a distinctive name but the loop gives me an error every time

7 visualizzazioni (ultimi 30 giorni)
Simulations =
1×50 cell array
%now I tried to build a loop which converts every cell into a matrix and names the matrices
for i = 1:50
a(i) = table2array(Simulations{1,i})
end
%this gives me the following error-> Unable to perform assignment because the left and right sides have a different number of elements.
  1 Commento
Stephen23
Stephen23 il 4 Mag 2018
"i would like to convert the different tables into matrices and give them a distinctive name"
Do NOT do that. Dynamically creating/accessing variable names is how beginners force themselves into writing slow, complex, buggy code that is hard to debug. Just use a cell array with indexing. Indexing is neat, easy to debug, and very efficient. Read this to know more:

Accedi per commentare.

Risposte (1)

sloppydisk
sloppydisk il 3 Mag 2018
You cannot store matrices inside matrices, you can however leave them inside the cell and convert them there using table2array:
% construct tables in cell
a = cell(1, 50);
b = rand(780, 6);
a(:) = {table(b(:, 1), b(:, 2), b(:, 3), b(:, 4), b(:, 5), b(:, 6))};
class(a{1})
% convert data to doubles in cell
a(:) = {table2array(a{:})};
class(a{1})
Note that a(1) gives a 1x1 cell, while a{1} gives the contents of that cell.

Categorie

Scopri di più su Cell Arrays in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by