# how can i overcome this error ?

3 visualizaciones (últimos 30 días)
amir el 11 de Sept. de 2013
t = 0:0.0001:0.07;
v0 = input('please Enter the value for v0:');
R = input('please Enter the value for resistance:');
C = input('please Enter the value for capacitacne:');
f = input('please Enter the value for frequency:');
m = length(t);
state = 'on';
for A = 1:m
switch state
case 'on'
vs(A) = v0 * sin(2*pi*f*t(A));
vR(A) = vs(A);
iR = vR(A)/R;
iC = 2*pi*f*C*v0*cos(2*pi*f*t(A));
I = iC + iR;
if I<=0
state = 'off';
tA = t(A);
end
case 'off'
vR(A) = v0*sin(2*pi*f*tA)*exp(-(t(A)-tA)/(R * C));
if vs(A) >= vR(A)
state = 'on';
end
end
end
plot (t,vs,':',t,vR,'k')
Error:
??? Attempted to access vs(45); index out of bounds because numel(vs)=44.
Error in ==> untitled1 at 24
if vs(A) >= vR(A)
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Walter Roberson el 11 de Sept. de 2013
In the case of 'off', you make an assignment to vR(A) but not to vs(A), but then you attempt to compare vR(A) to the (non-existent) vs(A). You need to decide what value vs(A) should have at that point and make sure the assignment happens.
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Categorías

Más información sobre Instrument Control Toolbox Supported Hardware en Help Center y File Exchange.

### Etiquetas

Aún no se han introducido etiquetas.

### Community Treasure Hunt

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

Start Hunting!

Translated by