I have the table K below and would like to use an if statement that replaces the zeros in the fifth column with 300, everytime that the row one below contains a "Ja".
My if statement looks like this:
if K(i,2:5)=="Ja"
K(i-1,6) = 300
end
This is the error I get: Index in position 1 is invalid. Array indices must be positive integers or logical values.
What do I need to change to access the correct data?
Thank you for your help!

답변 (1개)

Cris LaPierre
Cris LaPierre 2021년 11월 2일

0 개 추천

Have you defined i? If not, it is sqrt(-1).
There error means i is either a decimal or negative number.
A=1:3;
% Works
A(2)
ans = 2
% doesn't work
A(1.5)
Array indices must be positive integers or logical values.

댓글 수: 3

Noush
Noush 2021년 11월 3일
I have now changed my loop to this, and have defined l and m. I now get the error that the use of the operator '=' is not correct, but when I change it to '==' it gives the error that this is not supported for tables. What to do?
Cris LaPierre
Cris LaPierre 2021년 11월 3일
When indexing a table, paretheses return a table while curly braces return an array. You need to use curly braces to extract the value from the table.
You can read more about accessing data in tables here.
Noush
Noush 2021년 11월 3일
thank you, this fixed my problem :)

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Tables에 대해 자세히 알아보기

제품

릴리스

R2020a

질문:

2021년 11월 2일

댓글:

2021년 11월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by