在八度创建二维脉冲 [英] Creating 2-D Pulse in Octave

查看:79
本文介绍了在八度创建二维脉冲的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在八度中创建一个2-D脉冲.它将包括 一个中间的框,外部的值为1.0和0.0. 2-D数组的大小为512.如何在Octave中做到这一点?

I want to create a 2-D pulse in Octave. It will consist of a box in the middle with value 1.0 and 0.0 outside. The size of the 2-D array is 512. How can I do this in Octave?

推荐答案

给出存储在widthheight中的此框的宽度和高度,并假设它们对于 odd 对称,这很简单:

Given the width and height of this box stored in width and height, and assuming that they are both odd for symmetry, it's very simply:

row_half = floor(height/2);
col_half = floor(width/2);
pul = zeros(512,512);
pul(256-row_half:256+row_half, 256-col_half:256+col_half) = 1;

前两行代码确定所定义框的宽度和高度的一半.接下来,我们使用中间的(256,256)并确保我们的宽度介于左右两个宽度的一半之间,而顶部和底部的高度则占一半.这将填满您的盒子的总面积,这是通过第四行的索引完成的,我们将这些位置设置为1.

The first two lines of code determine what half the width and height of the defined box is. Next, we use the middle (256,256) and make sure we span from half the width both left and right, and half the height both top and bottom. This fills up the total area of your box and that is done by the indexing on the fourth line and we set these locations to 1.

输出的2D脉冲"存储在变量pul中.上述代码的前提条件是确保宽度和高度完全包含在512 x 512网格内.如果没有,八度会给你一个错误,超出范围.

The output 2D "pulse" is stored in the variable pul. A pre-condition of the above code is to make sure that your width and height are fully contained within the 512 x 512 grid. If not, Octave will give you an error going out of bounds.

假设我的宽度和高度均为101.如果我们做了imagesc(pul);

Let's say my width and height were both 101. We get this pulse, if we did imagesc(pul);

这篇关于在八度创建二维脉冲的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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