用 Octave 语言创建矩阵 A = [4 ... 128]
您能帮忙了解如何使用简化方式在Octave中创建矩阵吗?
我需要(矩阵) A = [4, 8, 16, 32, 64, 128]; 想要使用类似 A = [4: *2 : 128] (意味着 start = 4,step = *2 : finish = 128),但这在 Octave 中不起作用。
矩阵 B = [1 4 9 16 25 36] 也需要执行同样的操作,其中步骤一开始为 3,下一步增加 2。
有什么想法吗?
Can you help to know how to create a matrix in Octave using a shortened way?
I need to have (matrix) A = [4, 8, 16, 32, 64, 128];
Want to use something like A = [4: *2 : 128] (meaning start = 4, step = *2 : finish = 128), but this doesn't work in Octave.
The same needs to be done to matrix B = [1 4 9 16 25 36], where step is 3 at the beginning and is increasing by 2 on the next step.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用冒号运算符,您只能执行相同大小的步骤。但请注意,您的矩阵
具有结构
[2^2, 2^3, 2^4, ..., 2^7]
,因此您可以利用广播并将其定义为或 简单
With the colon operator you can only do steps of the same size. But notice that your matrix
has the structure
[2^2, 2^3, 2^4, ..., 2^7]
, so you can make use of broadcasting and define it asor simply
您可以使用循环来完成该任务。您只需要在循环语句中编写一致的规则即可。一种可能的方法如下:
You can use a loop for that task. You just need to write a consistent rule in the statments of your loop. A possible way to do that is the following: