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)
Show older comments
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
0 Comments
Accepted Answer
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
More Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!