How to best construct a matrix whose elements are exactly their indices or functions of the indices in Matlab?

前端 未结 5 646
陌清茗
陌清茗 2020-12-02 00:18

What is the best way to construct a matrix whose elements are exactly their indices in Matlab?


EDIT: The existing answers to this question is applicable to how

5条回答
  •  甜味超标
    2020-12-02 00:51

    Another option using repmat (since the content of these matrices is redundant):

    X=repmat((1:size(YourMatrix, 2))', 1, size(YourMatrix, 1));
    Y=repmat(1:size(YourMatrix, 1), size(YourMatrix, 2), 1);
    

提交回复
热议问题