[英]Subtracting an array from an integer in MATLAB
I think I'm having a hard time understanding the code below in MATLAB.我想我很难理解 MATLAB 中的以下代码。 I've expected A
to be [3,2,1,0]
but it actually returned [3,4]
.我预计A
是[3,2,1,0]
但它实际上返回了[3,4]
。 Why does this happen?为什么会这样?
numberpoints = 1;
x = 4;
A = x-numberpoints:x;
This is what it's doing:这就是它正在做的事情:
> (x-numberpoints):x % (4-1):4 or 3:4
ans =
3 4
To get your expected output:要获得您预期的 output:
> x-(numberpoints:x) % 4-(1:4)
ans =
3 2 1 0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.