1

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?

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

1 Comment

Oh... I assumed that zeros(500) created a 500x1 array. If I do foo=zeros(500, 1), it works.
0

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

como soluciono esto?

2 Comments

Please provide answer in english
Note that's a question, not a answer: you don't even need to translate, the question mark shows that. "How I solve this?"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.