adding column ( cell) to matrix

25 次查看(过去 30 天)
MOH
MOH 2021-11-9
评论: MOH 2021-11-9
I created a vector cell that I want to add it to existing matrix
I'm getting below error
Inconsistent concatenation dimensions because a 24-by-3 'double' array was converted
to a 1-by-1 'cell' array. Consider creating arrays of the same type before concatenating.
here is how I created the cell
Facies=cell(length(data),1);
Facies(1:2,1)={'cat'};
Facies(3:5,1)={'dog'};
Facies(6:24,1)={'mouse'};

回答(3 个)

Sulaymon Eshkabilov
x = 1:25; % Vector
F = {x} % Cell Array
F = 1×1 cell array
{[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25]}
H = x + F{:}
H = 1×25
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50

Sulaymon Eshkabilov
WHat you are trying to do is to augment all variables into one array, correct? In this case, table array might be a good one, e.g.:
x = (1:5).'; % Vector
F1 = categorical({'A'; 'B'; 'C'; 'D'; 'E'}); % Cell Categorical Array
F2 = categorical({'W'; 'U'; 'X'; 'Y'; 'Z'}); % Cell Categorical Array
T = array2table(F1);
T.F2 = F2;
T.x = x
T = 5×3 table
F1 F2 x __ __ _ A W 1 B U 2 C X 3 D Y 4 E Z 5
  1 个评论
MOH
MOH 2021-11-9
I converted everything to table
each column in the table is defined as cell ,
I need to get the mean for each column, how I can convert this cell table to variable to get the avr and mean?
I have four columns , 3 as cell and one as 'cell array of character vectors'

请先登录,再进行评论。


Sulaymon Eshkabilov
x = (1:5).'; % Vector
F1 = categorical({'A'; 'B'; 'C'; 'D'; 'E'}); % Cell Categorical Array
F2 = categorical({'W'; 'U'; 'X'; 'Y'; 'Z'}); % Cell Categorical Array
T = array2table(F1);
T.F2 = F2;
T.x = x;
Mean_x = mean(T.x)
Mean_x = 3
  1 个评论
MOH
MOH 2021-11-9
it is not working with my data , I'm gettting error
Error using categorical/subsasgn (line 38)
Attempt to assign field of non-structure array.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by