Error says "Subscript indices must either be real positive integers or logicals"
6 次查看(过去 30 天)
显示 更早的评论
x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 9, 8, 7, 6, 5, 4, 3, 2, 1];
n = -9:9;
x1 = 5*x(n-2) - 3*x(n+4)
How to remove this error?
1 个评论
Sam Chak
2023-11-1
编辑:Sam Chak
2023-11-1
What is variable n? It seems that n indicates the relative position (left and right) from the mean of the data set x, which is an array. In array indexing in MATLAB, the sequential position are assigned as positive integers that begins from 1 (Python indexing starts at 0). This is the Rule in MATLAB.
回答(1 个)
Arun
2023-11-1
Hey,
here, the variable 'x' has index values ranging from 1 to 19. So to remove the error keep the index value with in that range of 1 to 19. For n-2 and n+4 both to be in range 1 to 19 the supported value for are in range 3 to 15. You can use the following code:
x = [1,2,3,4,5,6,7,8,9,9,9,8,7,6,5,4,3,2,1];
n = 3:15;
x1 = 5 * x(n-2) - 3*x(n+4)
another workaround can be to restructure the equation with respect to the size of 'x', one possible way is:
x = [1,2,3,4,5,6,7,8,9,9,9,8,7,6,5,4,3,2,1];
n = -9:9;
n = n + 10;
x1 = 5 * x(n)-2 - 3*x(n)+4
Hope this gives you an idea to proceed.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!