如何使用特定值初始化矩阵的所有条目? [英] How do I initialise all entries of a matrix with a specific value?

查看:15
本文介绍了如何使用特定值初始化矩阵的所有条目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Haskell 中,如果我想获得一个包含 10 个元素的列表只包含数字 5,我可以这样做:

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

输出:

[5,5,5,5,5,5,5,5,5,5]

Matlab 中有这样的东西吗?

Is there anything like this in Matlab?

推荐答案

给数组赋值很容易:

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

或使用 repmat

repmat(5, 1, 10)

这篇关于如何使用特定值初始化矩阵的所有条目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆