how can i resolve the "index in position 2 is invalid" error in line 99? the code works fine when N=15 but i need N=17.

5 views (last 30 days)
clear
clc
tg=tfinal/(rept-1);
rt=(0:tg:tfinal);
rt(1)=1;
rt(rept)=tfinal;
for i=1:rept
ts(i)=rt(i)*dt; %times in seconds
end
ts(1)=0;
for j=1:rept
for i=1:N
ntd(i,1,:)=r(i);
ntd(i,2,j)=T(i,rt(j));
end
end
Index in position 2 is invalid. Array indices must be positive integers or logical values.

Accepted Answer

Walter Roberson
Walter Roberson on 8 Apr 2023
timegap=tfinal/(rept-1);
rt=0:timegap:tfinal;
rt(1)=1;
rt(rept)=tfinal
Timegap is not certain to be an integer, so rt can contain non-integer values.
ntd(i,2,j)=T(i,rt(j));
but you use rt as an index into T.
  3 Comments

Sign in to comment.

More Answers (0)

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!