How to automatically create variables which are column extracts from a matrix

前端 未结 4 565
被撕碎了的回忆
被撕碎了的回忆 2021-01-20 11:34

I have an n*n matrix and I want to extract every 3 columns and keep the result in different variables.

I know that it is possible to do it in this way:

4条回答
  •  半阙折子戏
    2021-01-20 12:10

    You can use:

    C = mat2cell(A,size(A,1),ones(size(A,2)/3,1)*3);
    

    It will split your matrix into subcells.

    You can access the information contained by those cells with:

    C{1}
    C{2}  %and so on
    

提交回复
热议问题