简体   繁体   English

矩阵矩阵的复杂matlab

[英]complex matlab for loop with matrix

I don't understand this piece of code of a for loop in matlab, I know that loops in matlab usually look like: for ii=1:2:100 so that it starts in 1 until 100 and in each iteration you add 2. But here I've got this condition in the loop and I don't get what it does: 我不了解matlab中for循环的这段代码,我知道matlab中的循环通常看起来像: for ii=1:2:100所以它从1开始直到100,在每次迭代中加2。但是在这里,我在循环中遇到了这种情况,但我不了解它的作用:

for ii=[1:w:rd(1)-w-border, rd(1)-w-border+1],
   ...
end;

w and border are integers passed as arguments and rd is size of the image/matrix ( rd = size(image); ) wborder是作为参数传递的整数, rd是图像/矩阵的rd = size(image);

Can someone explain me how for loops work in matlab with this kind of condition? 有人可以解释我在这种情况下for循环如何在matlab中工作吗? Thanks in advance. 提前致谢。

the for argument is a vector. for参数是一个向量。 the loop iterator ii takes one value for the vector for each iteration of the loop. 循环迭代器ii在循环的每次迭代中为向量取一个值。 As you mentioned, the vector can be equally spaced one like 1:2:100 . 正如您所提到的,向量可以像1:2:100一样均匀间隔。 But it can also be arbitrary, for example for ii = [4,6,1,8] ... . 但是它也可以是任意的,例如for ii = [4,6,1,8] ...
In you case the for argument vector is partly "equally spaced" vector: 1:w:rd(1)-w-border plus another element rd(1)-border+1 . 在这种情况下, for参数向量是部分“等距”向量: 1:w:rd(1)-w-border加上另一个元素rd(1)-border+1

For loop in matlab can execute statements for a defined set of index values: For example, the following code will display all the element in the set [1,5,8,17] : matlab中的For循环可以为一组定义的索引值执行语句:例如,以下代码将显示集合[1,5,8,17]中的所有元素:

for s = [1,5,8,17]
 disp(s)
end

Your code for ii=[1:w:rd(1)-w-border, rd(1)-w-border+1] is similar. for ii=[1:w:rd(1)-w-border, rd(1)-w-border+1]的代码与此类似。 Its just like a set 1:w:rd(1)-w-border with an additional element rd(1)-w-border+1 . 就像集合1:w:rd(1)-w-border以及附加元素rd(1)-w-border+1

Its like writing this set [1,2,3,4,5,8] as [1:1:5, 8] I hope its clear now. 就像将这组[1,2,3,4,5,8]写成[1:1:5, 8] [1,2,3,4,5,8]一样[1:1:5, 8]我希望现在可以清楚了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM