【问题标题】:"Invalid Index" error in ScilabScilab 中的“无效索引”错误
【发布时间】:2015-11-15 06:22:46
【问题描述】:

我正在使用以下代码:

for t = linspace(0,2,500)   

   x(t) = 1+ t^2;   
   y(t) = 2*t;  
   r(t) = sqrt((x(t))^2+(y(t))^2);  

   radius = 1.6

   if r(t) > 0.999*radius & r(t) < 1.001*radius then
       solucion = t;

   end
end;

disp(solucion, "the solution is:")

这适用于t > 1 和不同的半径值。

但是当 t 取 0 到 1 之间的值时,我得到 error 21: Invalid index

我也需要处理这些价值观。我该如何处理?

【问题讨论】:

  • 如果它像 MATLAB 一样工作,你只能用正整数索引东西。使用一个数组(例如0:0.01:1)并使用您的循环变量访问它,它是整数

标签: matlab scilab


【解决方案1】:

正如概述中所回答的那样:

Scilab 和 MATLAB 中的数组索引必须是正整数(或逻辑,但这绝对不是您想要的)。如果您需要 t 在从 0 开始的范围内变化,请始终写入 x(t+1)。如果您需要非整数值,仍然遍历整数并从循环索引计算非整数值。

【讨论】:

  • 不知道“0”不是有效索引:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-12
  • 2018-03-05
  • 1970-01-01
  • 2022-01-24
  • 1970-01-01
  • 2019-02-13
相关资源
最近更新 更多