convert cell to array
4 次查看(过去 30 天)
显示 更早的评论
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,:});
0 个评论
采纳的回答
Andrei Bobrov
2019-2-15
out = cat(1,A{:});
out = out(out ~= 0);
2 个评论
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]}
B = A{:} % why do i get only the first element of cell array ?
B = A(:) % this does not have problem
why does the parenthetical referencing with { : } return only the first element of cell array ? but it does not occur with ( : )
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Cell Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!