MATLAB: Index must be a positive integer or logical.

indexpositive value

hi, I'm trying to solve a half wave rectifier problem. But i'm getting an error as
Attempted to access v(1.1); index must be a positive integer or logical.
Error in ==> Untitled at 4
v(t)=0.1*sin(t)
Also i'm getting single discrete value in the plot
Here is my code
clear all; close all;
for t=1:0.1:2*pi
if t<pi
v(t)=0.1*sin(t)
else
v(t)=0;
end
stem(t,v);
end
Please help me to solve dis…..

Best Answer

Dear one possible way is this.
clear all; close all;
figure;
hold on;
index = 1;
for t=1:0.1:2*pi
if t<pi
v(index)=0.1*sin(t);
else
v(index)=0;
end
stem(t,v(index));
index = index + 1;
end
I just have removed your syntax error with best of my understanding. As you want to plot stem for each value of t. I m not sure either you get your desired result or not. Check if it works.