Info
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
Error:Subscript indices must either be real positive integers or logicals
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
I am fairly new to MATLAB and I am still learning the tricks to it. In this program I am trying to make, I want the program to calculate average power in two separate (but similar in design) AC circuits with 2 impedance and then plot these average power values vs. x. One impedance is a variable impedance where one impedance has its phase (x) varying from -50 degrees to 50 degrees and the other circuit contains the complex conjugate of this variable impedance. To keep these 2 circuits separate, I defined 2 different average power values to be calculated,(Pavg1 and Pavg2). I defined x to be a range from -50 to 50 with increments at 0.01. When I run my program, I get the error seen above and I am not certain as to why. Below is my code:
x = -50:0.01:50;
Zs = 20 + (20i);
Z01(x) = 20 + (x*1i);
Z02(x) = 20 - (x*1i);
Ztotal1(x) = Zs + Z01;
Ztotal2(x) = Zs + Z02;
I1(x) = 240/Ztotal1;
I2(x) = 240/Ztotal2;
Pavg1(x) = (240*I1(x))/2;
Pavg2(x) = (240*I2(x))/2;
Plot(x,Pavg1(x));
Plot(x,Pavg2(x))
And MATLAB says that my error is on Line 3 (Z01(x)).
Any help for a semi-beginner to MATLAB is appreciated. Thank you ahead of time for any help.
0 comentarios
Respuestas (2)
Iain
el 22 de Sept. de 2014
Editada: Iain
el 22 de Sept. de 2014
The simple answer, which should work is to drop all of the (x) you've got.
The reason being that it looks like you're confusing a "function" with a "vector".
To define a function, on the fly:
Z01 = @(x) (20+x*i); %The second load of () are optional, but I find they make it clearer.
Z01(-5.45641) will then give you an answer
3 comentarios
La pregunta está cerrada.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!