Subscript indices must either be real positive integers or logicals.

Yes, I went through the board to see if any of the peoples relate to my question. However, I cannot figure out from them how my problem it's self should appear.
This is my code:
Vla = [];
t = 0:.1:10;
Vs = zeros(length(t),length(t));
for m = 0:length(t)
for n = 0:length(t)
Vs(m,n) = (3.*exp(-t./3)).*sin(pi.*t);
if Vs > 0
Vla = Vs;
else
if Vs <= 0
Vla = 0;
end
end
end
end
plot(t,Vla),xlabel('Time (t)'),ylabel('Voltage (Vla)')
The problem has to do with the Vs, I am sure, but I cannot figure out how to adjust it for it to work properly. I am wondering if my code it's self is all kinds of wrong, or it is just the Vs.
Again I keep getting this code:
"Subscript indices must either be real positive integers or logicals."
Nothing else that goes along with it. No question marks, and not line indices.

Answers (1)

Vs(0) is not valid in matlab
Use instead
Vs(n+1,m+1)

1 Comment

It did not work, sorry. It just replaced my previous error with:
"Subscripted assignment dimension mismatch."
I swapped the Vs(m,n) = (3.*exp(-t./3)).*sin(pi.*t); with: Vs(m+1,n+1) = (3.*exp(-t./3)).*sin(pi.*t);

This question is closed.

Products

Asked:

on 26 Feb 2013

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!