convert cell to array

조회 수: 4 (최근 30일)
NA
NA 2019년 2월 15일
댓글: VBBV 2023년 2월 2일
I have
A={[1;95;110],[58;78;80;110;111;112],[58;59;79;110;112;113],[64;83;84;85;90;112;113],[112],[0],[0],[116]};
C = cellfun(@(x)x(x~=0),A,'uni',false);
I want to conver this cell to array, result should be:
result=[1;95;110;58;78;80;110;111;112;58;59;79;110;112;113;64;83;84;85;90;112;113;112;116]
I tried to use cell2mat(A) but have this error
Error using cat
Dimensions of arrays being concatenated are not consistent.
Error in cell2mat (line 75)
m{n} = cat(2,c{n,:});

채택된 답변

Andrei Bobrov
Andrei Bobrov 2019년 2월 15일
out = cat(1,A{:});
out = out(out ~= 0);
  댓글 수: 2
Badreddine Alane
Badreddine Alane 2020년 1월 27일
Thank you so much for the help.
VBBV
VBBV 2023년 2월 2일
A={[1;95;110],[58;78;80;110;111;112],[58;59;79;110;112;113],[64;83;84;85;90;112;113],[112],[0],[0],[116]}
A = 1×8 cell array
{3×1 double} {6×1 double} {6×1 double} {7×1 double} {[112]} {[0]} {[0]} {[116]}
B = A{:} % why do i get only the first element of cell array ?
B = 3×1
1 95 110
B = A(:) % this does not have problem
B = 8×1 cell array
{3×1 double} {6×1 double} {6×1 double} {7×1 double} {[ 112]} {[ 0]} {[ 0]} {[ 116]}
why does the parenthetical referencing with { : } return only the first element of cell array ? but it does not occur with ( : )

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Cell Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by