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

조회 수: 7 (최근 30일)
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)

채택된 답변

David Hill
David Hill 2020년 6월 4일
No loop needed.
[a,b]=pol2cart(Zp(:,3),Zp(:,2));
Zp=a+b.*i;
  댓글 수: 2
Julia Hariharan
Julia Hariharan 2020년 6월 4일
Thank you! I will try this now and let you know if it works.
Julia Hariharan
Julia Hariharan 2020년 6월 4일
That worked! I have some other issues with my code, but this one is resolved - thanks!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Antenna and Array Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by