Attempted to access (5,0); index must be a positive integer or logical

1 view (last 30 days)
Dear all, when I tried to plot the T vs. s diagram, the error "Attempted to access (5,0); index must be a positive integer or logical." shows up. When I switch T=0:1:30 to T=1:1:30, the diagram is very wrong. The good diagram only comes when I set t = 1:length(T). Could someone tells me why? Thanks a lot.
clear all;
Sigma = 5:5:30;
T = 0:1:30;
for sigma = Sigma;
for t = T;
s(sigma,t) = (sigma-3+0.072*t*(1+0.072*t))/0.77;
end;
end;
plot(s,T);

Accepted Answer

the cyclist
the cyclist on 23 Jan 2014
Is it better if you do this instead?
s(sigma,t+1) = (sigma-3+0.072*t*(1+0.072*t))/0.77;
Notice that I shifted your index, so that you start at 1 instead of 0.
  3 Comments
the cyclist
the cyclist on 24 Jan 2014
MATLAB has a 1-based indexing system, so you cannot write to the "zeroth element" of an array. Similarly, even if you wanted to plot at t=0.5, you could not write to the "0.5th element" of an array.
You just need to make a mapping from the values of t to the indices of your array. In this case, it is simply adding 1 to the value of t. You just need to be careful to label your resulting axes correctly

Sign in to comment.

More Answers (0)

Categories

Find more on Shifting and Sorting Matrices 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!