adding column ( cell) to matrix

24 Ansichten (letzte 30 Tage)
MOH
MOH am 9 Nov. 2021
Kommentiert: MOH am 9 Nov. 2021
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'};

Antworten (3)

Sulaymon Eshkabilov
Sulaymon Eshkabilov am 9 Nov. 2021
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
Sulaymon Eshkabilov am 9 Nov. 2021
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 Kommentar
MOH
MOH am 9 Nov. 2021
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'

Melden Sie sich an, um zu kommentieren.


Sulaymon Eshkabilov
Sulaymon Eshkabilov am 9 Nov. 2021
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 Kommentar
MOH
MOH am 9 Nov. 2021
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by