How do you insert a row or a column into a cell array?

Dear Matlab community
I want to insert a row or a column into a cell array. How could I conduct that?
Best regards
Benjamin

 채택된 답변

dpb
dpb 2022년 10월 9일
No differently than with any other array -- although inserting in the middle somewhere requires copying (although with cell arrays, the actual data won't be copied)
c={rand(2),rand(2)} % create starting cell array
c = 1×2 cell array
{2×2 double} {2×2 double}
c=[c(1) {rand(4,2)} c(2)] % insert a new cell in the middle
c = 1×3 cell array
{2×2 double} {4×2 double} {2×2 double}
NB: The cell array c itself must remain rectangular; as demonstrated the content in a cell can be anything. This with the orginal row vector can only insert a single row; with a 2D array will have to insert content for all rows/columns, etc., ...

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

태그

질문:

2022년 10월 9일

답변:

dpb
2022년 10월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by