Got an indexing error here. Please recommend an answer.

for i=1:9
N_matrix(1,i)=N(rem(i,3))*ex(i)/3; %(ERROR HERE)
end
Attempted to access N(0); index must be a positive integer or logical.
Error in practisee2 (line 227)
N_matrix(1,i+1)=N(rem(i+1,3))*ex(i+1)/3;

10 件のコメント

madhan ravi
madhan ravi 2018 年 10 月 16 日
did you see about indexing?
Walter Roberson
Walter Roberson 2018 年 10 月 16 日
rem(i,3) for integer i is going to give one of the results 0, 1, or 2. What output are you expecting if the rem gives 0 ?
Kevin Chng
Kevin Chng 2018 年 10 月 16 日
for i=1:9
N_matrix(1,i)=N(rem(i,3))*ex(i)/3;%(ERROR HERE)
end
when i =3, rem(3,3) will return 0, N(0) cause you error? Why?
N is one of your matrix/variable, index must be a positive integer or logical.
N(1) % No error
N(0) % error because it is not a positive integer
N(0.5) % error because it is not positive integer
N(-1) % error because it is not positive integer
KSSV
KSSV 2018 年 10 月 16 日
N(rem(i,3))
for i = 3, rem(i,3) will be zero.....and obviously you know that MATLAB do not have zero indexing. So the error. :)
Virajan Verma
Virajan Verma 2018 年 10 月 16 日
I am expecting 0 at rem(3,3), but N(0) is not accessable as shown above.
madhan ravi
madhan ravi 2018 年 10 月 16 日
upload your data N and let us know what you want N(rem(i,3)) with this syntax?
KSSV
KSSV 2018 年 10 月 16 日
編集済み: KSSV 2018 年 10 月 16 日
@ Virajan Verma you asked question yesterday that you are unable to access N(i) from i = 0:8, so we said MATLAB will not take indexing zero. It shall be positive non-zero integers. YOu accepted the answer. What have you learned from the question? You learned that N(0) is not right, it throws error. What is present question? It is same as above or not? It is not fair to ask every step a question in forum. I suggested/ adivced you to read basic tutorials of MATLAB which is very easy.
madhan ravi
madhan ravi 2018 年 10 月 16 日
exactly as KSSV says , would you mind uploading the so called mystery N ??
KSSV
KSSV 2018 年 10 月 16 日
N is a matrix formed from Shape functions. It is related FEM (Finite Element Method) stuff.
madhan ravi
madhan ravi 2018 年 10 月 16 日
thank you @KSSV

回答 (1 件)

Walter Roberson
Walter Roberson 2018 年 10 月 16 日

0 投票

N_matrix(1,i)=N(rem(i-1,3)+1)*ex(i)/3; %(ERROR HERE)

3 件のコメント

Virajan Verma
Virajan Verma 2018 年 10 月 16 日
@Walter Will this expression will result in the same output??
KSSV
KSSV 2018 年 10 月 16 日
Will this expression will result in the same output ..You try....play with values see the output..make a note..change the values....compare the output...remember you are learning..this is the way to learn.
Walter Roberson
Walter Roberson 2018 年 10 月 16 日
"Will this expression will result in the same output??"
No. Your original expression outputs an error message, whereas my proposed expression will execute.

この質問は閉じられています。

タグ

質問済み:

2018 年 10 月 16 日

閉鎖済み:

2021 年 8 月 20 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by