How do I initialise all entries of a matrix with a specific value?

后端 未结 5 1319
南笙
南笙 2020-12-14 06:04

In Haskell, if I wanted to get a 10 element list which only contained the number 5, I could do something like this:

take 10 $ repeat 5

Outp

5条回答
  •  被撕碎了的回忆
    2020-12-14 06:28

    It is easy to assign repeated values to an array:

    x(1:10) = 5;
    

    If you want to generate the array of elements inline in a statement try something like this:

    ones(1,10) * 5
    

    or with repmat

    repmat(5, 1, 10)
    

提交回复
热议问题