ITKeyword,专注技术干货聚合推荐

注册 | 登录

解决matlab - Invalid index error in Scilab when trying to access array element

itPublisher 分享于

2020腾讯云双十一活动,全年最低!!!(领取3500元代金券),
地址https://cloud.tencent.com/act/cps/redirect?redirect=1073

2020阿里云最低价产品入口,含代金券(新老用户有优惠),
地址https://www.aliyun.com/minisite/goods

I'm not sure why I can't do this in Scilab.

-->foo=zeros(500);

-->foo(300)
         !--error 21 
Invalid index.

Why do I get the 'Invalid index' error? I thought I had initialized foo as an array with 500 elements, each of which was set to 0?

matlab scilab
|
  this question
asked Nov 6 '10 at 10:14 Pieter 8,996 52 131 198

 | 

3 Answers
3

解决方法

If zeros in Scilab behaves just like zeros in Matlab the call zeros(500) creates a 500x500 array of 0s. That said, foo(300) would be a valid Matlab expression as Matlab understands what it calls 'linear indexing' on arrays of rank greater than 1.

If zeros in Scilab does bot behave just like zeros in Matlab I can't help.


|
  this answer
answered Nov 6 '10 at 10:46 High Performance Mark 62.7k 7 66 122      Oh... I assumed that zeros(500) created a 500x1 array. If I do foo=zeros(500, 1), it works. –  Pieter Nov 6 '10 at 10:59

 | 

In Scilab, you have to give both the number of rows as well as the number of columns. So, if you want to create a 500x500 matrix, you need to say zeros(500, 500). If you want a 500x1 vector, you need to say zeros(500, 1).

If you want to create a zeros matrix that has precisely as many rows and columns as another matrix (say A), you need to say zeros(A). This is where the confusion stems from.

In Scilab, zeros(500) would take 500 as a 1x1 matrix and generate a zeros matrix of size 1x1, that is [0]. In MATLAB, zeros(500) would take 500 to be the size of the matrix required, assuming a square matrix.


|
  this answer
answered Nov 9 '10 at 15:07 Aditya Sengupta 413 2 7

 | 

printf("%d\n",Md(y,u)) !--error 21 Índice inválido. at line 69 of exec file called by :

como soluciono esto?


|
  this answer
answered May 19 '14 at 17:39 santiago muñoz 1      Please provide answer in english –  Lal May 19 '14 at 18:02      Note that's a question, not a answer: you don't even need to translate, the question mark shows that. "How I solve this?" –  Gustavo Rodrigues Mar 21 '15 at 23:01

 | 


相关阅读排行


相关内容推荐

最新文章

×

×

请激活账号

为了能正常使用评论、编辑功能及以后陆续为用户提供的其他产品,请激活账号。

您的注册邮箱: 修改

重新发送激活邮件 进入我的邮箱

如果您没有收到激活邮件,请注意检查垃圾箱。