adding column ( cell) to matrix

조회 수: 29 (최근 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
Sulaymon Eshkabilov 2021년 11월 9일
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 2021년 11월 9일
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
Sulaymon Eshkabilov 2021년 11월 9일
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