How can I perform an operation on each element of a vector individually using a for loop?

20 visualizaciones (últimos 30 días)
I have impedance values from a separate file saved as a vector, the second column is the magnitude and the third column is the phase. I want to convert the magnitude and phase to compelx form for a set of frequency values, but when I try to do it for every frequency value it results in a single impedance value which is not what I want. This is what my code looks like right now. My issue is with the second for loop.
%Frequency from scan
Sweep;
for k=2:1:50
F(:,k)
s=2*pi*F*i;
end
%Impedance from scan, converted to complex
for j=1:1:49
Zp=Zp(j,2)*cos(Zp(j,3))+i*Zp(j,2)*cos(Zp(j,3))
end
%Line Impedance Calculations
LineImpedanceCalculation;
%Impedance Matrix Formulation
num6=0*F;
den6=1;
sys6=num6/den6;
num7=0*F;
den7=1;
sys7=num7/den7;
%Node 1
Z11=Zp+sys1+sys3
Z12=sys1+sys6+sys7
Z13=sys3+sys6+sys7
%Node 2
Z21=sys1+sys6+sys7
Z22=Zp+sys2+sys1
Z23=sys2+sys6+sys7
%Node 2
Z31=sys3+sys6+sys7;
Z32=sys2+sys6+sys7;
Z33=Zp+sys2+sys1;
%Final Impedance Matrix
Zmat = [Z11; Z21; Z31]
%Admittance Matrix and Eigenvalues
Ymat = inv(Zmat)
X=eig(Ymat)

Respuesta aceptada

David Hill
David Hill el 4 de Jun. de 2020
No loop needed.
[a,b]=pol2cart(Zp(:,3),Zp(:,2));
Zp=a+b.*i;
  2 comentarios
Julia Hariharan
Julia Hariharan el 4 de Jun. de 2020
That worked! I have some other issues with my code, but this one is resolved - thanks!

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by